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

IsAlreadyAdded() protected method

Checks if an assembly is already added. The method parses all references and compares the full assemblynames, or the location of the assemblies to decide whether two assemblies are the same.
protected IsAlreadyAdded ( ReferenceNode &existingReference ) : bool
existingReference ReferenceNode
return bool
        protected internal override bool IsAlreadyAdded(out ReferenceNode existingReference)
        {
            ReferenceContainerNode referencesFolder = this.ProjectMgr.FindChild(ReferenceContainerNode.ReferencesNodeVirtualName) as ReferenceContainerNode;
            Debug.Assert(referencesFolder != null, "Could not find the References node");
            bool shouldCheckPath = !string.IsNullOrEmpty(this.Url);

            for(HierarchyNode n = referencesFolder.FirstChild; n != null; n = n.NextSibling)
            {
                AssemblyReferenceNode assemblyReferenceNode = n as AssemblyReferenceNode;
                if(null != assemblyReferenceNode)
                {
                    // We will check if the full assemblynames are the same or if the Url of the assemblies is the same.
                    if(String.Compare(assemblyReferenceNode.AssemblyName.FullName, this.assemblyName.FullName, StringComparison.OrdinalIgnoreCase) == 0 ||
                        (shouldCheckPath && NativeMethods.IsSamePath(assemblyReferenceNode.Url, this.Url)))
                    {
                        existingReference = assemblyReferenceNode;
                        return true;
                    }
                }
            }

            existingReference = null;
            return false;
        }