/// <summary> /// Evaluates this leaf expression's resource type and/or path, starting at the specified json scope, with the contained <c>LeafExpressionOperator</c>. /// </summary> /// <param name="jsonScope">The json to evaluate.</param> /// <returns>Zero or more results of the evaluation, depending on whether there are any/multiple resources of the given type, /// and if the path contains any wildcards.</returns> public override IEnumerable <JsonRuleResult> Evaluate(IJsonPathResolver jsonScope) { if (jsonScope == null) { throw new ArgumentNullException(nameof(jsonScope)); } List <IJsonPathResolver> scopesToEvaluate = new List <IJsonPathResolver>(); if (!string.IsNullOrEmpty(ResourceType)) { scopesToEvaluate.AddRange(jsonScope.ResolveResourceType(ResourceType)); } else { scopesToEvaluate.Add(jsonScope); } foreach (var scope in scopesToEvaluate) { var leafScope = scope?.Resolve(Path); foreach (var propertyToEvaluate in leafScope) { yield return(new JsonRuleResult { Passed = Operator.EvaluateExpression(propertyToEvaluate.JToken), JsonPath = propertyToEvaluate.Path }); } } }
private IEnumerable <JsonRuleResult> EvaluateScope(IJsonPathResolver jsonPathResolver) { if (jsonPathResolver == null) { throw new ArgumentNullException(nameof(jsonPathResolver)); } var leafScope = jsonPathResolver?.Resolve(Path); foreach (var propertyToEvaluate in leafScope) { yield return(new JsonRuleResult { RuleDefinition = this.Rule, Passed = Operator.EvaluateExpression(propertyToEvaluate.JToken) }); } }
/// <summary> /// Evaluates this leaf expression's resource type and/or path, starting at the specified json scope, with the contained <c>LeafExpressionOperator</c>. /// </summary> /// <param name="jsonScope">The json to evaluate.</param> /// <returns>Zero or more results of the evaluation, depending on whether there are any/multiple resources of the given type, /// and if the path contains any wildcards.</returns> public override IEnumerable <JsonRuleResult> Evaluate(IJsonPathResolver jsonScope) { List <JsonRuleResult> results = new List <JsonRuleResult>(); if (!string.IsNullOrEmpty(ResourceType)) { var resourceResolver = new ResourceResolver(ResourceType, jsonScope.JToken); foreach (var resource in resourceResolver.Resources) { var resolver = new JsonPathResolver(resource, resource.Path); results.AddRange(EvaluateScope(resolver)); } } else { results.AddRange(EvaluateScope(jsonScope)); } return(results); }
/// <summary> /// Executes this <c>Expression</c> against a template. /// </summary> /// <param name="jsonScope">The template to evaluate</param> public abstract IEnumerable <JsonRuleResult> Evaluate(IJsonPathResolver jsonScope);