Microsoft.VisualStudio.Project.ComReferenceNode.IsAlreadyAdded C# (CSharp) Method

IsAlreadyAdded() public method

Checks if a reference is already added. The method parses all references and compares the FinalItemSpec and the GUID.
public IsAlreadyAdded ( ReferenceNode &existingEquivalentNode ) : bool
existingEquivalentNode ReferenceNode
return bool
        public override bool IsAlreadyAdded(out ReferenceNode existingEquivalentNode)
        {
            ReferenceContainerNode referencesFolder = this.ProjectManager.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
            Debug.Assert(referencesFolder != null, "Could not find the References node");

            for(HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                ComReferenceNode referenceNode = n as ComReferenceNode;

                if(referenceNode != null)
                {
                    // We check if the name and GUIDs are the same
                    if(referenceNode.TypeGuid == this.TypeGuid && String.Equals(referenceNode.Caption, this.Caption, StringComparison.OrdinalIgnoreCase))
                    {
                        existingEquivalentNode = referenceNode;
                        return true;
                    }
                }
            }

            existingEquivalentNode = null;
            return false;
        }