Example #1
0
        private static void DeterminePropertyPathOrDeferr(Type type, ICollection <RulePaths> propertiesToFind, ConcurrentDictionary <Type, List <DryvRuleDefinition> > deferredRules, DryvRuleDefinition rule)
        {
            var targetType           = rule.ValidationExpression.Parameters.First().Type;
            var currentTypeHierarchy = type.GetTypeHierarchyAndInterfaces().ToHashSet();
            var pathToPropertyInRule = rule.ModelPath.Split('.')
                                       .Where(s => !string.IsNullOrWhiteSpace(s))
                                       .ToList();

            if (!pathToPropertyInRule.Any() && !currentTypeHierarchy.Contains(targetType))
            {
                // The rule is defined on the current type, but it doesnt affect the current
                // type at all --> deferr rule until we're on the type matching the rule.
                deferredRules.GetOrAdd(targetType, _ => new List <DryvRuleDefinition>()).Add(rule);
            }
            else
            {
                // From the current node in the model tree, calculate
                // the path to the property that for which the rule is defined.
                pathToPropertyInRule.Add(rule.Property.Name.ToCamelCase());
                propertiesToFind.Add(new RulePaths(rule, pathToPropertyInRule));
            }
        }
Example #2
0
 public RulePaths(DryvRuleDefinition rule, List <string> path)
 {
     this.Rule = rule;
     this.Path = path;
 }