Пример #1
0
            public override bool Evaluate(object value, ModelPathSettings settings, Func <string, string>?propertyNameTransformer)
            {
                Preconditions.NotNull(value, nameof(value));

                var valueType = value.GetType();
                var contract  = JsonHelper.InternalPrivateContractResolver.ResolveContract(valueType);

                if (!(contract is JsonObjectContract objectContract))
                {
                    throw new InvalidOperationException($"value's type must resolve to a json object contract");
                }
                var propertyName = propertyNameTransformer?.Invoke(PropertyName) ?? PropertyName;
                var property     = objectContract.Properties.GetClosestMatchProperty(propertyName);

                if (property == null)
                {
                    throw new InvalidOperationException($"Could not find property {propertyName} on {valueType}");
                }

                var    retrievedValue = property.ValueProvider.GetValue(value);
                string?defaultValue   = null;

                if (retrievedValue == null && settings != null && settings.DefaultValues?.TryGetValue(propertyName, out defaultValue) == true)
                {
                    retrievedValue = defaultValue !;
                }
                return(string.Equals(Value, retrievedValue?.ToString() ?? "false", StringComparison.OrdinalIgnoreCase));
            }
Пример #2
0
 public virtual bool Evaluate(object value, ModelPathSettings settings, Func <string, string>?propertyNameTransformer) => _terms.All(term => term.Evaluate(value, settings, propertyNameTransformer));