public static object FindModel(this ModelTreeInfo tree, string path, object currentModel, IDictionary <object, object> cache) { var value = cache.GetOrAdd($"{tree.GetHashCode()}|{path}", _ => tree.FindModel(path)); return(!(value is string) && value is IEnumerable enumerable && enumerable.Cast <object>().Contains(currentModel) ? currentModel : value); }
public static object FindModel(this ModelTreeInfo tree, string path) { if (tree.ModelsByPath.TryGetValue(path, out var model)) { return(model); } var orderedItems = tree.ModelsByPath.OrderByDescending(i => i.Key.Length).ToList(); var current = orderedItems.First(); var k = current.Key.Substring(0, current.Key.Length - path.Length); if (k.EndsWith(".")) { k = k.Substring(0, k.Length - 1); } return(orderedItems.FirstOrDefault(i => i.Key == k).Value); }
private IEnumerable <DryvRuleTreeNode> FindRulesForProperty(Type rootModelType, PropertyInfo property, Func <Type, object> services, ModelTreeInfo treeInfo, RuleType ruleType) { var modelPath = treeInfo.ModelsByPath.Keys.OrderBy(k => k.Length).Last(); return(from rule in this.ruleFinder.GetRulesForProperty(rootModelType, property, ruleType, modelPath) where this.ruleEvaluator.IsEnabled(rule.Rule, services) select rule); }