public static TNode GetNode <TNodeType, TNode>(this IContainerNode <TNodeType> containerNode, TNodeType nodeType, IEqualityComparer <TNodeType> nodeTypeEqualityComparer) where TNode : Node <TNodeType> { Contract.Requires(containerNode != null); var node = containerNode.GetNode(nodeType, nodeTypeEqualityComparer); return(node != null ? (TNode)node : null); }
public static TNode GetOrAddNode <TNodeType, TNode>(this IContainerNode <TNodeType> containerNode, TNodeType nodeType, Func <TNode> nodeFactoryMethod, IEqualityComparer <TNodeType> nodeTypeEqualityComparer) where TNode : Node <TNodeType> { Contract.Requires(containerNode != null); Contract.Requires(nodeFactoryMethod != null); Contract.Requires(nodeTypeEqualityComparer != null); // Try and get an existing node from the container node. var existingNode = containerNode.GetNode <TNodeType, TNode>(nodeType, nodeTypeEqualityComparer); if (existingNode != null) { return(existingNode); } // Add new node to the container node. var newNode = nodeFactoryMethod(); containerNode.Add(newNode); return(newNode); }
public static Node <TNodeType> GetNode <TNodeType>(this IContainerNode <TNodeType> containerNode, TNodeType nodeType) { Contract.Requires(containerNode != null); return(containerNode.GetNode <TNodeType>(nodeType, Node <TNodeType> .DefaultNodeTypeEqualityComarer)); }