private static MatchList FindRelationshipsSafe <TRelationshipDef>(IRelationshipDefCol relationshipDefCol, MatchesConditionDelegate <TRelationshipDef> matchesConditionDelegate, List <IRelationshipDefCol> alreadyChecked) where TRelationshipDef : RelationshipDef { var listOfPaths = new MatchList(); if (matchesConditionDelegate == null) { return(listOfPaths); } if (relationshipDefCol == null) { return(listOfPaths); } if (alreadyChecked.Contains(relationshipDefCol)) { return(listOfPaths); } alreadyChecked.Add(relationshipDefCol); foreach (var relationshipDef in relationshipDefCol) { var relationshipName = relationshipDef.RelationshipName; var castedRelationshipDef = relationshipDef as TRelationshipDef; if (castedRelationshipDef == null) { continue; } var matchesCondition = matchesConditionDelegate(castedRelationshipDef); if (matchesCondition) { listOfPaths.Add(relationshipName, null); } else { var classDef = (ClassDef)relationshipDef.RelatedObjectClassDef; if (classDef != null) { var results = FindRelationshipsSafe(classDef.RelationshipDefCol, matchesConditionDelegate, alreadyChecked); if (results.Count > 0) { listOfPaths.Add(relationshipName, results); } } } } return(listOfPaths); }
/// <summary> /// Returns a list of all relationships that match the Delegate relationship. /// </summary> /// <typeparam name="TRelationshipDef"></typeparam> /// <param name="relationshipDefCol"></param> /// <param name="matchesConditionDelegate"></param> /// <returns></returns> public static MatchList FindRelationships <TRelationshipDef>(IRelationshipDefCol relationshipDefCol, MatchesConditionDelegate <TRelationshipDef> matchesConditionDelegate) where TRelationshipDef : RelationshipDef { return(FindRelationshipsSafe(relationshipDefCol, matchesConditionDelegate, new List <IRelationshipDefCol>())); }