/// <summary> /// Finds the first Ruleset matching the selector argument that inherits from or is of type TRuleset (pass this as Ruleset if /// you are trying to find ANY Ruleset that matches the selector) /// </summary> public IEnumerable <Closure> FindRulesets(Selector selector) { var matchingRuleSets = Frames .Select(frame => frame.Find <Ruleset>(this, selector, null)) .Select( matchedClosuresList => matchedClosuresList.Where( matchedClosure => { if (!Frames.Any(frame => frame.IsEqualOrClonedFrom(matchedClosure.Ruleset))) { return(true); } var mixinDef = matchedClosure.Ruleset as MixinDefinition; if (mixinDef != null) { return(mixinDef.Condition != null); } return(false); } ) ) .FirstOrDefault(matchedClosuresList => matchedClosuresList.Count() != 0); if (matchingRuleSets != null) { return(matchingRuleSets); } if (Parent != null) { matchingRuleSets = Parent.FindRulesets(selector); } if (matchingRuleSets != null) { return(matchingRuleSets); } if (ClosureEnvironment != null) { return(ClosureEnvironment.FindRulesets(selector)); } return(null); }
/// <summary> /// Finds the first Ruleset matching the selector argument that inherits from or is of type TRuleset (pass this as Ruleset if /// you are trying to find ANY Ruleset that matches the selector) /// </summary> public IEnumerable <Closure> FindRulesets(Selector selector) { var matchingRuleSets = Frames .Reverse() .SelectMany(frame => frame.Find <Ruleset>(this, selector, null)) .Where(matchedClosure => { if (!Frames.Any(frame => frame.IsEqualOrClonedFrom(matchedClosure.Ruleset))) { return(true); } var mixinDef = matchedClosure.Ruleset as MixinDefinition; if (mixinDef != null) { return(mixinDef.Condition != null); } return(false); }).ToList(); if (matchingRuleSets.Any()) { return(matchingRuleSets); } if (Parent != null) { var parentRulesets = Parent.FindRulesets(selector); if (parentRulesets != null) { return(parentRulesets); } } if (ClosureEnvironment != null) { return(ClosureEnvironment.FindRulesets(selector)); } return(null); }