in src/Analyzer.JsonRuleEngine/Expressions/Expression.cs [69:107]
protected IEnumerable<JsonRuleEvaluation> EvaluateInternal(IJsonPathResolver jsonScope, Func<IJsonPathResolver, IEnumerable<JsonRuleEvaluation>> doEvaluation)
{
if (jsonScope == null) throw new ArgumentNullException(nameof(jsonScope));
// Select resources of given type, if specified
IEnumerable<IJsonPathResolver> scopesToEvaluate;
if (!string.IsNullOrEmpty(ResourceType))
{
scopesToEvaluate = jsonScope.ResolveResourceType(ResourceType);
}
else
{
scopesToEvaluate = new[] { jsonScope };
}
List<JsonRuleEvaluation> evaluations = new List<JsonRuleEvaluation>();
foreach (var initialScope in scopesToEvaluate)
{
// Expand with path if specified
IEnumerable<IJsonPathResolver> expandedScopes = Path == null ?
new[] { initialScope }.AsEnumerable() :
initialScope?.Resolve(Path);
foreach (var propertyToEvaluate in expandedScopes)
{
// Evaluate this path if either (a) there is no Where condition to evaluate, or (b) the Where expression passed for this path.
// Do not pass a line number resolver to Where because line numbers in these evaluations do not matter.
var whereEvaluation = Where?.Evaluate(propertyToEvaluate, jsonLineNumberResolver: null);
if (whereEvaluation == null || whereEvaluation.Any(w => w.Passed && w.HasResults))
{
// Perform the evaluation on this scope/path
evaluations.AddRange(doEvaluation(propertyToEvaluate));
}
}
}
return evaluations;
}