-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve model and evaluation of conditions
- Loading branch information
Showing
9 changed files
with
82 additions
and
70 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
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,59 +1,16 @@ | ||
using System; | ||
using ConfigCat.Client.Utils; | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
using Newtonsoft.Json; | ||
#else | ||
using System.Text.Json.Serialization; | ||
#endif | ||
|
||
namespace ConfigCat.Client; | ||
|
||
/// <summary> | ||
/// Base interface for conditions. | ||
/// </summary> | ||
public interface ICondition { } | ||
|
||
internal struct ConditionWrapper | ||
internal interface IConditionProvider | ||
{ | ||
private object? condition; | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
[JsonProperty(PropertyName = "t")] | ||
#else | ||
[JsonPropertyName("t")] | ||
#endif | ||
public ComparisonCondition? ComparisonCondition | ||
{ | ||
readonly get => this.condition as ComparisonCondition; | ||
set => ModelHelper.SetOneOf(ref this.condition, value); | ||
} | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
[JsonProperty(PropertyName = "s")] | ||
#else | ||
[JsonPropertyName("s")] | ||
#endif | ||
public SegmentCondition? SegmentCondition | ||
{ | ||
readonly get => this.condition as SegmentCondition; | ||
set => ModelHelper.SetOneOf(ref this.condition, value); | ||
} | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
[JsonProperty(PropertyName = "d")] | ||
#else | ||
[JsonPropertyName("d")] | ||
#endif | ||
public PrerequisiteFlagCondition? PrerequisiteFlagCondition | ||
{ | ||
readonly get => this.condition as PrerequisiteFlagCondition; | ||
set => ModelHelper.SetOneOf(ref this.condition, value); | ||
} | ||
Condition? GetCondition(bool throwIfInvalid = true); | ||
} | ||
|
||
public readonly ICondition? GetCondition(bool throwIfInvalid = true) | ||
{ | ||
return this.condition as ICondition | ||
?? (!throwIfInvalid ? null : throw new InvalidOperationException("Condition is missing or invalid.")); | ||
} | ||
internal abstract class Condition : ICondition, IConditionProvider | ||
{ | ||
public Condition? GetCondition(bool throwIfInvalid = true) => this; | ||
} |
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,54 @@ | ||
using System; | ||
using ConfigCat.Client.Utils; | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
using Newtonsoft.Json; | ||
#else | ||
using System.Text.Json.Serialization; | ||
#endif | ||
|
||
namespace ConfigCat.Client; | ||
|
||
internal struct ConditionContainer : IConditionProvider | ||
{ | ||
private object? condition; | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
[JsonProperty(PropertyName = "t")] | ||
#else | ||
[JsonPropertyName("t")] | ||
#endif | ||
public ComparisonCondition? ComparisonCondition | ||
{ | ||
readonly get => this.condition as ComparisonCondition; | ||
set => ModelHelper.SetOneOf(ref this.condition, value); | ||
} | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
[JsonProperty(PropertyName = "s")] | ||
#else | ||
[JsonPropertyName("s")] | ||
#endif | ||
public SegmentCondition? SegmentCondition | ||
{ | ||
readonly get => this.condition as SegmentCondition; | ||
set => ModelHelper.SetOneOf(ref this.condition, value); | ||
} | ||
|
||
#if USE_NEWTONSOFT_JSON | ||
[JsonProperty(PropertyName = "d")] | ||
#else | ||
[JsonPropertyName("d")] | ||
#endif | ||
public PrerequisiteFlagCondition? PrerequisiteFlagCondition | ||
{ | ||
readonly get => this.condition as PrerequisiteFlagCondition; | ||
set => ModelHelper.SetOneOf(ref this.condition, value); | ||
} | ||
|
||
public readonly Condition? GetCondition(bool throwIfInvalid = true) | ||
{ | ||
return this.condition as Condition | ||
?? (!throwIfInvalid ? null : throw new InvalidOperationException("Condition is missing or invalid.")); | ||
} | ||
} |
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