internal T RegisterOrReuseChild <T>(T child) where T : EntityNode { // Reuse exact matches without re-registering if (ChildEntityNodes.Contains(child)) { return(child); } EntityNode existing = null; // Reuse relationships var asRelationship = child as AccessRelationshipNode; if (asRelationship != null) { // Check to see if there's already a matching relationship node registered // If so, reuse it existing = ChildEntityNodes .OfType <AccessRelationshipNode>() .FirstOrDefault(rr => rr.AreEquivalent(asRelationship)); } // Reuse parameters var asParameter = child as EntityParameterNode; if (asParameter != null) { // Check to see if there's already a matching parameter node registered here // If so, reuse it existing = ChildEntityNodes .OfType <EntityParameterNode>() .FirstOrDefault(rr => rr.ParameterName == asParameter.ParameterName); } if (existing != null) { // Only allow an existing node to be reused if neither are coming from a variable, or if both are coming from the same variable // (Otherwise reuse means sub-clauses in the variable won't be able to find their parent container) if (child.RootForVariableContainer == existing.RootForVariableContainer) { return(existing as T); } } ChildEntityNodes.Add(child); return(child); }
internal void RegisterChild(EntityNode child) { ChildEntityNodes.Add(child); }