From 2848429b2eb6c8634d4d1b5a179d260300c87782 Mon Sep 17 00:00:00 2001 From: Adam Simon Date: Thu, 7 Sep 2023 11:56:33 +0200 Subject: [PATCH] Rename Comparator/ComparisonCondition to UserComparator/UserCondition to align naming with the agreed terminology --- benchmarks/NewVersionLib/BenchmarkHelper.cs | 20 +-- .../Evaluation/EvaluateLogHelper.cs | 148 +++++++++--------- .../Evaluation/RolloutEvaluator.cs | 104 ++++++------ .../Models/ConditionContainer.cs | 4 +- src/ConfigCatClient/Models/Segment.cs | 16 +- .../{Comparator.cs => UserComparator.cs} | 4 +- ...omparisonCondition.cs => UserCondition.cs} | 23 ++- 7 files changed, 159 insertions(+), 160 deletions(-) rename src/ConfigCatClient/Models/{Comparator.cs => UserComparator.cs} (98%) rename src/ConfigCatClient/Models/{ComparisonCondition.cs => UserCondition.cs} (75%) diff --git a/benchmarks/NewVersionLib/BenchmarkHelper.cs b/benchmarks/NewVersionLib/BenchmarkHelper.cs index 3311a5f9..bcae1598 100644 --- a/benchmarks/NewVersionLib/BenchmarkHelper.cs +++ b/benchmarks/NewVersionLib/BenchmarkHelper.cs @@ -37,10 +37,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor { new ConditionContainer { - ComparisonCondition = new ComparisonCondition() + UserCondition = new UserCondition() { ComparisonAttribute = nameof(User.Identifier), - Comparator = Comparator.SensitiveOneOf, + Comparator = UserComparator.SensitiveOneOf, StringListValue = new[] { "61418c941ecda8031d08ab86ec821e676fde7b6a59cd16b1e7191503c2f8297d", @@ -57,10 +57,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor { new ConditionContainer { - ComparisonCondition = new ComparisonCondition() + UserCondition = new UserCondition() { ComparisonAttribute = nameof(User.Email), - Comparator = Comparator.Contains, + Comparator = UserComparator.Contains, StringListValue = new[] { "@example.com" } } }, @@ -73,10 +73,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor { new ConditionContainer { - ComparisonCondition = new ComparisonCondition() + UserCondition = new UserCondition() { ComparisonAttribute = "Version", - Comparator = Comparator.SemVerOneOf, + Comparator = UserComparator.SemVerOneOf, StringListValue = new[] { "1.0.0", "2.0.0" } } }, @@ -89,10 +89,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor { new ConditionContainer { - ComparisonCondition = new ComparisonCondition() + UserCondition = new UserCondition() { ComparisonAttribute = "Version", - Comparator = Comparator.SemVerGreaterThan, + Comparator = UserComparator.SemVerGreaterThan, StringValue = "3.0.0" } }, @@ -105,10 +105,10 @@ public class BasicMatrixTestsDescriptor : IMatrixTestDescriptor { new ConditionContainer { - ComparisonCondition = new ComparisonCondition() + UserCondition = new UserCondition() { ComparisonAttribute = "Number", - Comparator = Comparator.NumberGreaterThan, + Comparator = UserComparator.NumberGreaterThan, DoubleValue = 3.14 } }, diff --git a/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs b/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs index d38e6052..101af873 100644 --- a/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs +++ b/src/ConfigCatClient/Evaluation/EvaluateLogHelper.cs @@ -19,21 +19,21 @@ public static IndentedTextBuilder AppendEvaluationResult(this IndentedTextBuilde return builder.Append(result ? "true" : "false"); } - private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, object? comparisonValue) + private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, object? comparisonValue) { return builder.Append($"User.{comparisonAttribute} {comparator.ToDisplayText()} '{comparisonValue ?? InvalidValuePlaceholder}'"); } - private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, string? comparisonValue, bool isSensitive = false) + private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, string? comparisonValue, bool isSensitive = false) { - return builder.AppendComparisonCondition(comparisonAttribute, comparator, !isSensitive ? (object?)comparisonValue : ""); + return builder.AppendUserCondition(comparisonAttribute, comparator, !isSensitive ? (object?)comparisonValue : ""); } - private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, string[]? comparisonValue, bool isSensitive = false) + private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, string[]? comparisonValue, bool isSensitive = false) { if (comparisonValue is null) { - return builder.AppendComparisonCondition(comparisonAttribute, comparator, (object?)null); + return builder.AppendUserCondition(comparisonAttribute, comparator, (object?)null); } const string valueText = "value", valuesText = "values"; @@ -51,11 +51,11 @@ private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBu } } - private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, string? comparisonAttribute, Comparator comparator, double? comparisonValue, bool isDateTime = false) + private static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, string? comparisonAttribute, UserComparator comparator, double? comparisonValue, bool isDateTime = false) { if (comparisonValue is null) { - return builder.AppendComparisonCondition(comparisonAttribute, comparator, (object?)null); + return builder.AppendUserCondition(comparisonAttribute, comparator, (object?)null); } return isDateTime && DateTimeUtils.TryConvertFromUnixTimeSeconds(comparisonValue.Value, out var dateTime) @@ -63,50 +63,50 @@ private static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBu : builder.Append($"User.{comparisonAttribute} {comparator.ToDisplayText()} '{comparisonValue.Value}'"); } - public static IndentedTextBuilder AppendComparisonCondition(this IndentedTextBuilder builder, ComparisonCondition condition) + public static IndentedTextBuilder AppendUserCondition(this IndentedTextBuilder builder, UserCondition condition) { return condition.Comparator switch { - Comparator.Contains or - Comparator.NotContains or - Comparator.SemVerOneOf or - Comparator.SemVerNotOneOf => - builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue), - - Comparator.SemVerLessThan or - Comparator.SemVerLessThanEqual or - Comparator.SemVerGreaterThan or - Comparator.SemVerGreaterThanEqual => - builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue), - - Comparator.NumberEqual or - Comparator.NumberNotEqual or - Comparator.NumberLessThan or - Comparator.NumberLessThanEqual or - Comparator.NumberGreaterThan or - Comparator.NumberGreaterThanEqual => - builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue), - - Comparator.SensitiveOneOf or - Comparator.SensitiveNotOneOf or - Comparator.SensitiveTextStartsWith or - Comparator.SensitiveTextNotStartsWith or - Comparator.SensitiveTextEndsWith or - Comparator.SensitiveTextNotEndsWith or - Comparator.SensitiveArrayContains or - Comparator.SensitiveArrayNotContains => - builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue, isSensitive: true), - - Comparator.DateTimeBefore or - Comparator.DateTimeAfter => - builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue, isDateTime: true), - - Comparator.SensitiveTextEquals or - Comparator.SensitiveTextNotEquals => - builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue, isSensitive: true), + UserComparator.Contains or + UserComparator.NotContains or + UserComparator.SemVerOneOf or + UserComparator.SemVerNotOneOf => + builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue), + + UserComparator.SemVerLessThan or + UserComparator.SemVerLessThanEqual or + UserComparator.SemVerGreaterThan or + UserComparator.SemVerGreaterThanEqual => + builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue), + + UserComparator.NumberEqual or + UserComparator.NumberNotEqual or + UserComparator.NumberLessThan or + UserComparator.NumberLessThanEqual or + UserComparator.NumberGreaterThan or + UserComparator.NumberGreaterThanEqual => + builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue), + + UserComparator.SensitiveOneOf or + UserComparator.SensitiveNotOneOf or + UserComparator.SensitiveTextStartsWith or + UserComparator.SensitiveTextNotStartsWith or + UserComparator.SensitiveTextEndsWith or + UserComparator.SensitiveTextNotEndsWith or + UserComparator.SensitiveArrayContains or + UserComparator.SensitiveArrayNotContains => + builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringListValue, isSensitive: true), + + UserComparator.DateTimeBefore or + UserComparator.DateTimeAfter => + builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.DoubleValue, isDateTime: true), + + UserComparator.SensitiveTextEquals or + UserComparator.SensitiveTextNotEquals => + builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.StringValue, isSensitive: true), _ => - builder.AppendComparisonCondition(condition.ComparisonAttribute, condition.Comparator, condition.GetComparisonValue(throwIfInvalid: false)), + builder.AppendUserCondition(condition.ComparisonAttribute, condition.Comparator, condition.GetComparisonValue(throwIfInvalid: false)), }; } @@ -150,7 +150,7 @@ private static IndentedTextBuilder AppendConditions(this IndentedTex _ = conditions[i].GetCondition(throwIfInvalid: false) switch { - ComparisonCondition comparisonCondition => builder.AppendComparisonCondition(comparisonCondition), + UserCondition userCondition => builder.AppendUserCondition(userCondition), PrerequisiteFlagCondition prerequisiteFlagCondition => builder.AppendPrerequisiteFlagCondition(prerequisiteFlagCondition), SegmentCondition segmentCondition => builder.AppendSegmentCondition(segmentCondition), _ => builder.Append(InvalidItemPlaceholder), @@ -291,36 +291,36 @@ public static IndentedTextBuilder AppendSegment(this IndentedTextBuilder builder return builder.AppendConditions(segment.Conditions); } - public static string ToDisplayText(this Comparator comparator) + public static string ToDisplayText(this UserComparator comparator) { return comparator switch { - Comparator.Contains => "CONTAINS ANY OF", - Comparator.NotContains => "NOT CONTAINS ANY OF", - Comparator.SemVerOneOf => "IS ONE OF", - Comparator.SemVerNotOneOf => "IS NOT ONE OF", - Comparator.SemVerLessThan => "<", - Comparator.SemVerLessThanEqual => "<=", - Comparator.SemVerGreaterThan => ">", - Comparator.SemVerGreaterThanEqual => ">=", - Comparator.NumberEqual => "=", - Comparator.NumberNotEqual => "!=", - Comparator.NumberLessThan => "<", - Comparator.NumberLessThanEqual => "<=", - Comparator.NumberGreaterThan => ">", - Comparator.NumberGreaterThanEqual => ">=", - Comparator.SensitiveOneOf => "IS ONE OF", - Comparator.SensitiveNotOneOf => "IS NOT ONE OF", - Comparator.DateTimeBefore => "BEFORE", - Comparator.DateTimeAfter => "AFTER", - Comparator.SensitiveTextEquals => "EQUALS", - Comparator.SensitiveTextNotEquals => "NOT EQUALS", - Comparator.SensitiveTextStartsWith => "STARTS WITH ANY OF", - Comparator.SensitiveTextNotStartsWith => "NOT STARTS WITH ANY OF", - Comparator.SensitiveTextEndsWith => "ENDS WITH ANY OF", - Comparator.SensitiveTextNotEndsWith => "NOT ENDS WITH ANY OF", - Comparator.SensitiveArrayContains => "ARRAY CONTAINS ANY OF", - Comparator.SensitiveArrayNotContains => "ARRAY NOT CONTAINS ANY OF", + UserComparator.Contains => "CONTAINS ANY OF", + UserComparator.NotContains => "NOT CONTAINS ANY OF", + UserComparator.SemVerOneOf => "IS ONE OF", + UserComparator.SemVerNotOneOf => "IS NOT ONE OF", + UserComparator.SemVerLessThan => "<", + UserComparator.SemVerLessThanEqual => "<=", + UserComparator.SemVerGreaterThan => ">", + UserComparator.SemVerGreaterThanEqual => ">=", + UserComparator.NumberEqual => "=", + UserComparator.NumberNotEqual => "!=", + UserComparator.NumberLessThan => "<", + UserComparator.NumberLessThanEqual => "<=", + UserComparator.NumberGreaterThan => ">", + UserComparator.NumberGreaterThanEqual => ">=", + UserComparator.SensitiveOneOf => "IS ONE OF", + UserComparator.SensitiveNotOneOf => "IS NOT ONE OF", + UserComparator.DateTimeBefore => "BEFORE", + UserComparator.DateTimeAfter => "AFTER", + UserComparator.SensitiveTextEquals => "EQUALS", + UserComparator.SensitiveTextNotEquals => "NOT EQUALS", + UserComparator.SensitiveTextStartsWith => "STARTS WITH ANY OF", + UserComparator.SensitiveTextNotStartsWith => "NOT STARTS WITH ANY OF", + UserComparator.SensitiveTextEndsWith => "ENDS WITH ANY OF", + UserComparator.SensitiveTextNotEndsWith => "NOT ENDS WITH ANY OF", + UserComparator.SensitiveArrayContains => "ARRAY CONTAINS ANY OF", + UserComparator.SensitiveArrayNotContains => "ARRAY NOT CONTAINS ANY OF", _ => InvalidOperatorPlaceholder }; } diff --git a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs index bad8365e..b9d763e5 100644 --- a/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs +++ b/src/ConfigCatClient/Evaluation/RolloutEvaluator.cs @@ -251,8 +251,8 @@ private bool TryEvaluateConditions(TCondition[] conditions, Targetin switch (condition) { - case ComparisonCondition comparisonCondition: - conditionResult = EvaluateComparisonCondition(comparisonCondition, contextSalt, ref context, out error); + case UserCondition userCondition: + conditionResult = EvaluateUserCondition(userCondition, contextSalt, ref context, out error); newLineBeforeThen = conditions.Length > 1; break; @@ -296,12 +296,12 @@ private bool TryEvaluateConditions(TCondition[] conditions, Targetin return error is null; } - private bool EvaluateComparisonCondition(ComparisonCondition condition, string contextSalt, ref EvaluateContext context, out string? error) + private bool EvaluateUserCondition(UserCondition condition, string contextSalt, ref EvaluateContext context, out string? error) { error = null; var logBuilder = context.LogBuilder; - logBuilder?.AppendComparisonCondition(condition); + logBuilder?.AppendUserCondition(condition); if (context.User is null) { @@ -327,43 +327,43 @@ private bool EvaluateComparisonCondition(ComparisonCondition condition, string c var comparator = condition.Comparator; switch (comparator) { - case Comparator.SensitiveTextEquals: - case Comparator.SensitiveTextNotEquals: + case UserComparator.SensitiveTextEquals: + case UserComparator.SensitiveTextNotEquals: return EvaluateSensitiveTextEquals(userAttributeValue!, condition.StringValue, - EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, negate: comparator == Comparator.SensitiveTextNotEquals); + EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, negate: comparator == UserComparator.SensitiveTextNotEquals); - case Comparator.SensitiveOneOf: - case Comparator.SensitiveNotOneOf: + case UserComparator.SensitiveOneOf: + case UserComparator.SensitiveNotOneOf: return EvaluateSensitiveOneOf(userAttributeValue!, condition.StringListValue, - EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, negate: comparator == Comparator.SensitiveNotOneOf); + EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, negate: comparator == UserComparator.SensitiveNotOneOf); - case Comparator.SensitiveTextStartsWith: - case Comparator.SensitiveTextNotStartsWith: + case UserComparator.SensitiveTextStartsWith: + case UserComparator.SensitiveTextNotStartsWith: return EvaluateSensitiveTextSliceEquals(userAttributeValue!, condition.StringListValue, - EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, startsWith: true, negate: comparator == Comparator.SensitiveTextNotStartsWith); + EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, startsWith: true, negate: comparator == UserComparator.SensitiveTextNotStartsWith); - case Comparator.SensitiveTextEndsWith: - case Comparator.SensitiveTextNotEndsWith: + case UserComparator.SensitiveTextEndsWith: + case UserComparator.SensitiveTextNotEndsWith: return EvaluateSensitiveTextSliceEquals(userAttributeValue!, condition.StringListValue, - EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, startsWith: false, negate: comparator == Comparator.SensitiveTextNotEndsWith); + EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, startsWith: false, negate: comparator == UserComparator.SensitiveTextNotEndsWith); - case Comparator.Contains: - case Comparator.NotContains: - return EvaluateContains(userAttributeValue!, condition.StringListValue, negate: comparator == Comparator.NotContains); + case UserComparator.Contains: + case UserComparator.NotContains: + return EvaluateContains(userAttributeValue!, condition.StringListValue, negate: comparator == UserComparator.NotContains); - case Comparator.SemVerOneOf: - case Comparator.SemVerNotOneOf: + case UserComparator.SemVerOneOf: + case UserComparator.SemVerNotOneOf: if (!SemVersion.TryParse(userAttributeValue!.Trim(), out var version, strict: true)) { error = HandleInvalidSemVerUserAttribute(condition, context.Key, userAttributeName, userAttributeValue); return false; } - return EvaluateSemVerOneOf(version, condition.StringListValue, negate: comparator == Comparator.SemVerNotOneOf); + return EvaluateSemVerOneOf(version, condition.StringListValue, negate: comparator == UserComparator.SemVerNotOneOf); - case Comparator.SemVerLessThan: - case Comparator.SemVerLessThanEqual: - case Comparator.SemVerGreaterThan: - case Comparator.SemVerGreaterThanEqual: + case UserComparator.SemVerLessThan: + case UserComparator.SemVerLessThanEqual: + case UserComparator.SemVerGreaterThan: + case UserComparator.SemVerGreaterThanEqual: if (!SemVersion.TryParse(userAttributeValue!.Trim(), out version, strict: true)) { error = HandleInvalidSemVerUserAttribute(condition, context.Key, userAttributeName, userAttributeValue); @@ -371,12 +371,12 @@ private bool EvaluateComparisonCondition(ComparisonCondition condition, string c } return EvaluateSemVerRelation(version, comparator, condition.StringValue); - case Comparator.NumberEqual: - case Comparator.NumberNotEqual: - case Comparator.NumberLessThan: - case Comparator.NumberLessThanEqual: - case Comparator.NumberGreaterThan: - case Comparator.NumberGreaterThanEqual: + case UserComparator.NumberEqual: + case UserComparator.NumberNotEqual: + case UserComparator.NumberLessThan: + case UserComparator.NumberLessThanEqual: + case UserComparator.NumberGreaterThan: + case UserComparator.NumberGreaterThanEqual: if (!double.TryParse(userAttributeValue!.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var number)) { error = HandleInvalidNumberUserAttribute(condition, context.Key, userAttributeName, userAttributeValue); @@ -384,19 +384,19 @@ private bool EvaluateComparisonCondition(ComparisonCondition condition, string c } return EvaluateNumberRelation(number, condition.Comparator, condition.DoubleValue); - case Comparator.DateTimeBefore: - case Comparator.DateTimeAfter: + case UserComparator.DateTimeBefore: + case UserComparator.DateTimeAfter: if (!double.TryParse(userAttributeValue!.Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out number)) { error = HandleInvalidNumberUserAttribute(condition, context.Key, userAttributeName, userAttributeValue, isDateTime: true); return false; } - return EvaluateDateTimeRelation(number, condition.DoubleValue, before: comparator == Comparator.DateTimeBefore); + return EvaluateDateTimeRelation(number, condition.DoubleValue, before: comparator == UserComparator.DateTimeBefore); - case Comparator.SensitiveArrayContains: - case Comparator.SensitiveArrayNotContains: + case UserComparator.SensitiveArrayContains: + case UserComparator.SensitiveArrayNotContains: return EvaluateSensitiveArrayContains(userAttributeValue!, condition.StringListValue, - EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, negate: comparator == Comparator.SensitiveArrayNotContains); + EnsureConfigJsonSalt(context.Setting.ConfigJsonSalt), contextSalt, negate: comparator == UserComparator.SensitiveArrayNotContains); default: throw new InvalidOperationException("Comparison operator is invalid."); @@ -516,7 +516,7 @@ private static bool EvaluateSemVerOneOf(SemVersion version, string[]? comparison return result ^ negate; } - private static bool EvaluateSemVerRelation(SemVersion version, Comparator comparator, string? comparisonValue) + private static bool EvaluateSemVerRelation(SemVersion version, UserComparator comparator, string? comparisonValue) { EnsureComparisonValue(comparisonValue); @@ -529,26 +529,26 @@ private static bool EvaluateSemVerRelation(SemVersion version, Comparator compar return comparator switch { - Comparator.SemVerLessThan => comparisonResult < 0, - Comparator.SemVerLessThanEqual => comparisonResult <= 0, - Comparator.SemVerGreaterThan => comparisonResult > 0, - Comparator.SemVerGreaterThanEqual => comparisonResult >= 0, + UserComparator.SemVerLessThan => comparisonResult < 0, + UserComparator.SemVerLessThanEqual => comparisonResult <= 0, + UserComparator.SemVerGreaterThan => comparisonResult > 0, + UserComparator.SemVerGreaterThanEqual => comparisonResult >= 0, _ => throw new ArgumentOutOfRangeException(nameof(comparator), comparator, null) }; } - private static bool EvaluateNumberRelation(double number, Comparator comparator, double? comparisonValue) + private static bool EvaluateNumberRelation(double number, UserComparator comparator, double? comparisonValue) { var number2 = EnsureComparisonValue(comparisonValue).Value; return comparator switch { - Comparator.NumberEqual => number == number2, - Comparator.NumberNotEqual => number != number2, - Comparator.NumberLessThan => number < number2, - Comparator.NumberLessThanEqual => number <= number2, - Comparator.NumberGreaterThan => number > number2, - Comparator.NumberGreaterThanEqual => number >= number2, + UserComparator.NumberEqual => number == number2, + UserComparator.NumberNotEqual => number != number2, + UserComparator.NumberLessThan => number < number2, + UserComparator.NumberLessThanEqual => number <= number2, + UserComparator.NumberGreaterThan => number > number2, + UserComparator.NumberGreaterThanEqual => number >= number2, _ => throw new ArgumentOutOfRangeException(nameof(comparator), comparator, null) }; } @@ -719,14 +719,14 @@ private static T EnsureComparisonValue([NotNull] T? value) return value ?? throw new InvalidOperationException("Comparison value is missing or invalid."); } - private string HandleInvalidSemVerUserAttribute(ComparisonCondition condition, string key, string userAttributeName, string userAttributeValue) + private string HandleInvalidSemVerUserAttribute(UserCondition condition, string key, string userAttributeName, string userAttributeValue) { var reason = $"'{userAttributeValue}' is not a valid semantic version"; this.logger.UserObjectAttributeIsInvalid(condition.ToString(), key, reason, userAttributeName, condition.Comparator.ToDisplayText()); return string.Format(CultureInfo.InvariantCulture, InvalidUserAttributeError, userAttributeName, reason); } - private string HandleInvalidNumberUserAttribute(ComparisonCondition condition, string key, string userAttributeName, string userAttributeValue, bool isDateTime = false) + private string HandleInvalidNumberUserAttribute(UserCondition condition, string key, string userAttributeName, string userAttributeValue, bool isDateTime = false) { var reason = isDateTime ? $"'{userAttributeValue}' is not a valid Unix timestamp (number of seconds elapsed since Unix epoch)" diff --git a/src/ConfigCatClient/Models/ConditionContainer.cs b/src/ConfigCatClient/Models/ConditionContainer.cs index 80d1315e..b0968994 100644 --- a/src/ConfigCatClient/Models/ConditionContainer.cs +++ b/src/ConfigCatClient/Models/ConditionContainer.cs @@ -18,9 +18,9 @@ internal struct ConditionContainer : IConditionProvider #else [JsonPropertyName("t")] #endif - public ComparisonCondition? ComparisonCondition + public UserCondition? UserCondition { - readonly get => this.condition as ComparisonCondition; + readonly get => this.condition as UserCondition; set => ModelHelper.SetOneOf(ref this.condition, value); } diff --git a/src/ConfigCatClient/Models/Segment.cs b/src/ConfigCatClient/Models/Segment.cs index c44cccb2..9d5a9ce0 100644 --- a/src/ConfigCatClient/Models/Segment.cs +++ b/src/ConfigCatClient/Models/Segment.cs @@ -26,7 +26,7 @@ public interface ISegment /// /// The list of segment rule conditions (where there is a logical AND relation between the items). /// - IReadOnlyList Conditions { get; } + IReadOnlyList Conditions { get; } } internal sealed class Segment : ISegment @@ -40,7 +40,7 @@ internal sealed class Segment : ISegment string ISegment.Name => Name ?? throw new InvalidOperationException("Segment name is missing."); - private ComparisonCondition[]? conditions; + private UserCondition[]? conditions; #if USE_NEWTONSOFT_JSON [JsonProperty(PropertyName = "r")] @@ -48,16 +48,16 @@ internal sealed class Segment : ISegment [JsonPropertyName("r")] #endif [NotNull] - public ComparisonCondition[]? Conditions + public UserCondition[]? Conditions { - get => this.conditions ?? ArrayUtils.EmptyArray(); + get => this.conditions ?? ArrayUtils.EmptyArray(); set => this.conditions = value; } - private IReadOnlyList? conditionsReadOnly; - IReadOnlyList ISegment.Conditions => this.conditionsReadOnly ??= this.conditions is { Length: > 0 } - ? new ReadOnlyCollection(this.conditions) - : ArrayUtils.EmptyArray(); + private IReadOnlyList? conditionsReadOnly; + IReadOnlyList ISegment.Conditions => this.conditionsReadOnly ??= this.conditions is { Length: > 0 } + ? new ReadOnlyCollection(this.conditions) + : ArrayUtils.EmptyArray(); public override string ToString() { diff --git a/src/ConfigCatClient/Models/Comparator.cs b/src/ConfigCatClient/Models/UserComparator.cs similarity index 98% rename from src/ConfigCatClient/Models/Comparator.cs rename to src/ConfigCatClient/Models/UserComparator.cs index ff761f7b..cdc05f9d 100644 --- a/src/ConfigCatClient/Models/Comparator.cs +++ b/src/ConfigCatClient/Models/UserComparator.cs @@ -1,9 +1,9 @@ namespace ConfigCat.Client; /// -/// Comparison condition operator. +/// User condition operator. /// -public enum Comparator : byte +public enum UserComparator : byte { /// /// CONTAINS ANY OF - Does the comparison attribute contain any of the comparison values as a substring? diff --git a/src/ConfigCatClient/Models/ComparisonCondition.cs b/src/ConfigCatClient/Models/UserCondition.cs similarity index 75% rename from src/ConfigCatClient/Models/ComparisonCondition.cs rename to src/ConfigCatClient/Models/UserCondition.cs index cad62623..9467ca95 100644 --- a/src/ConfigCatClient/Models/ComparisonCondition.cs +++ b/src/ConfigCatClient/Models/UserCondition.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; using ConfigCat.Client.Utils; using ConfigCat.Client.Evaluation; @@ -13,9 +12,9 @@ namespace ConfigCat.Client; /// -/// Comparison condition. +/// User condition. /// -public interface IComparisonCondition : ICondition +public interface IUserCondition : ICondition { /// /// The User Object attribute that the condition is based on. Can be "User ID", "Email", "Country" or any custom attribute. @@ -25,17 +24,17 @@ public interface IComparisonCondition : ICondition /// /// The operator which defines the relation between the comparison attribute and the comparison value. /// - Comparator Comparator { get; } + UserComparator Comparator { get; } /// - /// The value that the attribute is compared to. Can be a value of the following types: (including a semantic version), or , where T is . + /// The value that the attribute is compared to. Can be a value of the following types: (including a semantic version), or , where T is . /// object ComparisonValue { get; } } -internal sealed class ComparisonCondition : Condition, IComparisonCondition +internal sealed class UserCondition : Condition, IUserCondition { - public const Comparator UnknownComparator = (Comparator)byte.MaxValue; + public const UserComparator UnknownComparator = (UserComparator)byte.MaxValue; #if USE_NEWTONSOFT_JSON [JsonProperty(PropertyName = "a")] @@ -44,16 +43,16 @@ internal sealed class ComparisonCondition : Condition, IComparisonCondition #endif public string? ComparisonAttribute { get; set; } - string IComparisonCondition.ComparisonAttribute => ComparisonAttribute ?? throw new InvalidOperationException("Comparison attribute name is missing."); + string IUserCondition.ComparisonAttribute => ComparisonAttribute ?? throw new InvalidOperationException("Comparison attribute name is missing."); - private Comparator comparator = UnknownComparator; + private UserComparator comparator = UnknownComparator; #if USE_NEWTONSOFT_JSON [JsonProperty(PropertyName = "c")] #else [JsonPropertyName("c")] #endif - public Comparator Comparator + public UserComparator Comparator { get => this.comparator; set => ModelHelper.SetEnum(ref this.comparator, value); @@ -96,7 +95,7 @@ public string[]? StringListValue private object? comparisonValueReadOnly; - object IComparisonCondition.ComparisonValue => this.comparisonValueReadOnly ??= GetComparisonValue() is var comparisonValue && comparisonValue is string[] stringListValue + object IUserCondition.ComparisonValue => this.comparisonValueReadOnly ??= GetComparisonValue() is var comparisonValue && comparisonValue is string[] stringListValue ? (stringListValue.Length > 0 ? new ReadOnlyCollection(stringListValue) : ArrayUtils.EmptyArray()) : comparisonValue!; @@ -110,7 +109,7 @@ public string[]? StringListValue public override string ToString() { return new IndentedTextBuilder() - .AppendComparisonCondition(this) + .AppendUserCondition(this) .ToString(); } }