Microsoft.VisualStudio.Project.SolutionListenerForProjectReferenceUpdate.GetProjectReferenceOnNodeForHierarchy C# (CSharp) Method

GetProjectReferenceOnNodeForHierarchy() private static method

private static GetProjectReferenceOnNodeForHierarchy ( IList references, IVsHierarchy inputHierarchy ) : ProjectReferenceNode
references IList
inputHierarchy IVsHierarchy
return ProjectReferenceNode
        private static ProjectReferenceNode GetProjectReferenceOnNodeForHierarchy(IList<ReferenceNode> references, IVsHierarchy inputHierarchy)
        {
            if(references == null || references.Count == 0)
            {
                return null;
            }

            Guid projectGuid;
            ErrorHandler.ThrowOnFailure(inputHierarchy.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out projectGuid));

            string canonicalName;
            ErrorHandler.ThrowOnFailure(inputHierarchy.GetCanonicalName(VSConstants.VSITEMID_ROOT, out canonicalName));
            foreach(ReferenceNode refNode in references)
            {
                ProjectReferenceNode projRefNode = refNode as ProjectReferenceNode;
                if(projRefNode != null)
                {
                    if(projRefNode.ReferencedProjectGuid == projectGuid)
                    {
                        return projRefNode;
                    }

                    // Try with canonical names, if the project that is removed is an unloaded project than the above criteria will not pass.
                    if(!String.IsNullOrEmpty(projRefNode.Url) && NativeMethods.IsSamePath(projRefNode.Url, canonicalName))
                    {
                        return projRefNode;
                    }
                }
            }

            return null;
        }