-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c6f160
commit c4d7e4b
Showing
8 changed files
with
88 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace ManagedCode.FeatureChecker.Tests; | ||
|
||
internal enum MyEnum | ||
{ | ||
feature1, | ||
feature2, | ||
feature3, | ||
feature4, | ||
feature5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,5 @@ | ||
using System.Collections.Immutable; | ||
using System.Text.Json.Serialization; | ||
namespace ManagedCode.FeatureChecker; | ||
|
||
namespace ManagedCode.FeatureChecker; | ||
public class FeatureHolder | ||
public class FeatureHolder : Dictionary<Enum, FeatureStatus> | ||
{ | ||
private Dictionary<string, FeatureStatus> _features; | ||
|
||
[JsonInclude] | ||
public ImmutableDictionary<string, FeatureStatus> Features | ||
{ | ||
get => _features.ToImmutableDictionary(); | ||
private set => _features = new Dictionary<string, FeatureStatus>(value); | ||
} | ||
|
||
|
||
public FeatureHolder() | ||
{ | ||
_features = new Dictionary<string, FeatureStatus>(); | ||
} | ||
|
||
public bool TryAddFeature(string featureName, FeatureStatus status) | ||
{ | ||
return ValidateFeatureName(featureName) | ||
? _features.TryAdd(featureName, status) | ||
: false; | ||
} | ||
|
||
public bool TryGetFeatureStatus(string featureName, out FeatureStatus status) | ||
{ | ||
status = default; | ||
|
||
return ValidateFeatureName(featureName) | ||
? _features.TryGetValue(featureName, out status) | ||
: false; | ||
} | ||
|
||
public void RemoveFeature(string featureName) | ||
{ | ||
if(ValidateFeatureName(featureName)) | ||
{ | ||
_features.Remove(featureName); | ||
} | ||
} | ||
|
||
public void UpdateFeatureStatus(string featureName, FeatureStatus status) | ||
{ | ||
if(!ValidateFeatureName(featureName)) | ||
{ | ||
return; | ||
} | ||
|
||
_features[featureName] = status; | ||
} | ||
|
||
|
||
private bool ValidateFeatureName(string featureName) | ||
{ | ||
return !string.IsNullOrWhiteSpace(featureName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ public enum FeatureStatus | |
{ | ||
Disabled, | ||
Enabled, | ||
Debug, | ||
} | ||
Debug | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace ManagedCode.FeatureChecker; | ||
|
||
public interface IFeatureChecker | ||
{ | ||
int Count { get; } | ||
bool IsFeatureExists(Enum feature); | ||
bool IsEnabled(Enum feature); | ||
bool IsDisabled(Enum feature); | ||
bool IsDebug(Enum feature); | ||
bool TryGetFeatureStatus(Enum feature, out FeatureStatus status); | ||
List<Enum> GetFeaturesByStatus(FeatureStatus status); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters