GetProjectExplorerReference() public static méthode

public static GetProjectExplorerReference ( string url, string assemblyName ) : string
url string
assemblyName string
Résultat string
        private void WriteReferences(StringBuilder sb)
        {
            sb.Append("<div class=\"folderTitle\">References</div>");
            sb.AppendLine("<div class=\"folder\">");

            var assemblyNames = new SortedSet <string>();

            foreach (var projectReference in Project.ProjectReferences.Select(p => Project.Solution.GetProject(p.ProjectId).AssemblyName))
            {
                assemblyNames.Add(projectReference);
            }

            foreach (var metadataReference in Project.MetadataReferences.Select(m => Path.GetFileNameWithoutExtension(m.Display)))
            {
                assemblyNames.Add(metadataReference);
            }

            foreach (var reference in ForwardedReferenceAssemblies)
            {
                assemblyNames.Add(reference);
            }

            var usedReferences = new HashSet <string>(this.UsedReferences, StringComparer.OrdinalIgnoreCase);

            foreach (var reference in assemblyNames)
            {
                var    externalIndex = this.SolutionGenerator.GetExternalAssemblyIndex(reference);
                string url           = "/#" + reference;
                if (externalIndex != -1)
                {
                    url = "@" + externalIndex.ToString() + "@#" + reference;
                    sb.AppendLine(Markup.GetProjectExplorerReference(url, reference));
                }
                else if ((SolutionGenerator.IsPartOfSolution(reference) || (reference?.Contains("->") ?? false)) && usedReferences.Contains(reference))
                {
                    sb.AppendLine(Markup.GetProjectExplorerReference(url, reference));
                }
                else
                {
                    sb.Append("<span class=\"referenceDisabled\">").Append(reference).AppendLine("</span>");
                }
            }

            sb.AppendLine("</div>");
        }
Exemple #2
0
        private void PatchProjectExplorer(ProjectFinalizer project)
        {
            if (project.ReferencingAssemblies.Count == 0 || project.ReferencingAssemblies.Count > 100)
            {
                return;
            }

            var fileName = Path.Combine(project.ProjectDestinationFolder, Constants.ProjectExplorer + ".html");

            if (!File.Exists(fileName))
            {
                return;
            }

            var           sourceLines = File.ReadAllLines(fileName);
            List <string> lines       = new List <string>(sourceLines.Length + project.ReferencingAssemblies.Count + 2);

            RelativeState state = RelativeState.Before;

            foreach (var sourceLine in sourceLines)
            {
                switch (state)
                {
                case RelativeState.Before:
                    if (sourceLine == "<div class=\"folderTitle\">References</div><div class=\"folder\">")
                    {
                        state = RelativeState.Inside;
                    }

                    break;

                case RelativeState.Inside:
                    if (sourceLine == "</div>")
                    {
                        state = RelativeState.InsertionPoint;
                    }

                    break;

                case RelativeState.InsertionPoint:
                    lines.Add("<div class=\"folderTitle\">Used By</div><div class=\"folder\">");

                    foreach (var referencingAssembly in project.ReferencingAssemblies)
                    {
                        string referenceHtml = Markup.GetProjectExplorerReference("/#" + referencingAssembly, referencingAssembly);
                        lines.Add(referenceHtml);
                    }

                    lines.Add("</div>");

                    state = RelativeState.After;
                    break;

                case RelativeState.After:
                    break;

                default:
                    break;
                }

                lines.Add(sourceLine);
            }

            File.WriteAllLines(fileName, lines);
        }