From 46485bb3214165295a016f3ce606b14124d45a7f Mon Sep 17 00:00:00 2001 From: Pilchie Date: Thu, 17 Apr 2014 16:37:29 -0700 Subject: [PATCH] Make our use of DebuggerDisplayAttribute more consistent (changeset 1234216) --- .../Core/FindSymbols/ReferenceLocation.cs | 10 +++------- Src/Workspaces/Core/FindSymbols/ReferencedSymbol.cs | 13 +++++-------- .../FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs | 7 ++++++- Src/Workspaces/Core/Workspace/Solution/Document.cs | 10 +++------- .../Core/Workspace/Solution/DocumentId.cs | 8 ++++---- .../Core/Workspace/Solution/DocumentState.cs | 2 +- Src/Workspaces/Core/Workspace/Solution/Project.cs | 10 +++------- Src/Workspaces/Core/Workspace/Solution/ProjectId.cs | 8 ++++---- .../Core/Workspace/Solution/ProjectReference.cs | 10 +++------- .../Core/Workspace/Solution/SolutionId.cs | 6 +++--- .../Core/Workspace/WorkspaceDiagnostic.cs | 12 +++++------- Src/Workspaces/CoreTest/ReferencedSymbolTests.cs | 6 +++--- Src/Workspaces/CoreTest/SolutionTests.cs | 2 +- 13 files changed, 44 insertions(+), 60 deletions(-) diff --git a/Src/Workspaces/Core/FindSymbols/ReferenceLocation.cs b/Src/Workspaces/Core/FindSymbols/ReferenceLocation.cs index e6e21852e10..a9cc3f663a8 100644 --- a/Src/Workspaces/Core/FindSymbols/ReferenceLocation.cs +++ b/Src/Workspaces/Core/FindSymbols/ReferenceLocation.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols /// /// Information about a reference to a symbol. /// - [DebuggerDisplay("{DebuggerDisplay,nq}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] public struct ReferenceLocation : IComparable, IEquatable { /// @@ -113,13 +113,9 @@ public int CompareTo(ReferenceLocation other) return 0; } - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private string DebuggerDisplay + private string GetDebuggerDisplay() { - get - { - return string.Format("{0}: {1}", this.Document.Name, this.Location); - } + return string.Format("{0}: {1}", this.Document.Name, this.Location); } } } \ No newline at end of file diff --git a/Src/Workspaces/Core/FindSymbols/ReferencedSymbol.cs b/Src/Workspaces/Core/FindSymbols/ReferencedSymbol.cs index e6155291cfe..2dcad5a34c7 100644 --- a/Src/Workspaces/Core/FindSymbols/ReferencedSymbol.cs +++ b/Src/Workspaces/Core/FindSymbols/ReferencedSymbol.cs @@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols /// how C# and VB allow a symbol to be both a definition and a reference at the same time (for /// example, a method which implements an interface method). /// - [DebuggerDisplay("{DebuggerDisplay,nq}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] public class ReferencedSymbol { /// @@ -34,14 +34,11 @@ internal ReferencedSymbol(ISymbol definition, IEnumerable loc this.Locations = (locations ?? SpecializedCollections.EmptyEnumerable()).ToReadOnlyCollection(); } - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - internal string DebuggerDisplay + /// Internal for testing purposes + internal string GetDebuggerDisplay() { - get - { - var count = this.Locations.Count(); - return string.Format("{0}, {1} {2}", this.Definition.Name, count, count == 1 ? "ref" : "refs"); - } + var count = this.Locations.Count(); + return string.Format("{0}, {1} {2}", this.Definition.Name, count, count == 1 ? "ref" : "refs"); } } } diff --git a/Src/Workspaces/Core/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs b/Src/Workspaces/Core/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs index 54c65e8e3de..c5cb718f19f 100644 --- a/Src/Workspaces/Core/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs +++ b/Src/Workspaces/Core/FindSymbols/SymbolTree/SymbolTreeInfo.Node.cs @@ -10,7 +10,7 @@ internal partial class SymbolTreeInfo /// A node represents a single unique name in a dotted-name tree. /// Uniqueness is always case sensitive. /// - [DebuggerDisplay("{Name,nq}, {ParentIndex}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] private struct Node { private readonly string name; @@ -43,6 +43,11 @@ public bool IsEquivalent(Node node) { return (node.Name == this.Name) && (node.ParentIndex == this.ParentIndex); } + + private string GetDebuggerDisplay() + { + return name + ", " + parentIndex; + } } } } \ No newline at end of file diff --git a/Src/Workspaces/Core/Workspace/Solution/Document.cs b/Src/Workspaces/Core/Workspace/Solution/Document.cs index d3166d9294c..b539abe8e2b 100644 --- a/Src/Workspaces/Core/Workspace/Solution/Document.cs +++ b/Src/Workspaces/Core/Workspace/Solution/Document.cs @@ -17,7 +17,7 @@ namespace Microsoft.CodeAnalysis /// Represents a source code document that is part of a project. /// It provides access to the source text, parsed syntax tree and the corresponding semantic model. /// - [DebuggerDisplay("{DebuggerDisplay,nq}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] public partial class Document { private readonly DocumentState state; @@ -470,13 +470,9 @@ internal async Task WithFrozenPartialSemanticsAsync(CancellationToken } } - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private string DebuggerDisplay + private string GetDebuggerDisplay() { - get - { - return this.Name; - } + return this.Name; } } } \ No newline at end of file diff --git a/Src/Workspaces/Core/Workspace/Solution/DocumentId.cs b/Src/Workspaces/Core/Workspace/Solution/DocumentId.cs index f003f6f81fe..57e6f1a9f69 100644 --- a/Src/Workspaces/Core/Workspace/Solution/DocumentId.cs +++ b/Src/Workspaces/Core/Workspace/Solution/DocumentId.cs @@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis /// An identifier that can be used to retrieve the same Document across versions of the /// workspace. /// - [DebuggerDisplay("{DebuggerText}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] [Serializable] public class DocumentId : IEquatable { @@ -44,14 +44,14 @@ public static DocumentId CreateNewId(ProjectId projectId, string debugName = nul return new DocumentId(projectId, debugName); } - internal string DebuggerText + internal string GetDebuggerDisplay() { - get { return string.Format("({0}, #{1} - {2})", this.GetType().Name, this.Id, this.debugName); } + return string.Format("({0}, #{1} - {2})", this.GetType().Name, this.Id, this.debugName); } public override string ToString() { - return DebuggerText; + return GetDebuggerDisplay(); } public override bool Equals(object obj) diff --git a/Src/Workspaces/Core/Workspace/Solution/DocumentState.cs b/Src/Workspaces/Core/Workspace/Solution/DocumentState.cs index 56d0154e840..03d188510e5 100644 --- a/Src/Workspaces/Core/Workspace/Solution/DocumentState.cs +++ b/Src/Workspaces/Core/Workspace/Solution/DocumentState.cs @@ -121,7 +121,7 @@ private static async Task LoadTextAsync(TextLoader loader, Docum catch (Exception e) { services.Workspace.OnWorkspaceFailed(new DocumentDiagnostic(WorkspaceDiagnosticKind.FileAccessFailure, e.Message, documentId)); - return TextAndVersion.Create(SourceText.From(string.Empty), VersionStamp.Default, documentId.DebuggerText); + return TextAndVersion.Create(SourceText.From(string.Empty), VersionStamp.Default, documentId.GetDebuggerDisplay()); } } diff --git a/Src/Workspaces/Core/Workspace/Solution/Project.cs b/Src/Workspaces/Core/Workspace/Solution/Project.cs index 13cd53d992e..304e5b31b4b 100644 --- a/Src/Workspaces/Core/Workspace/Solution/Project.cs +++ b/Src/Workspaces/Core/Workspace/Solution/Project.cs @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis /// /// Represents a project that is part of a solution. /// - [DebuggerDisplay("{DebuggerDisplay,nq}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] public partial class Project { private readonly Solution solution; @@ -548,13 +548,9 @@ public Project RemoveDocument(DocumentId documentId) return this.Solution.RemoveDocument(documentId).GetProject(this.Id); } - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private string DebuggerDisplay + private string GetDebuggerDisplay() { - get - { - return this.Name; - } + return this.Name; } } } \ No newline at end of file diff --git a/Src/Workspaces/Core/Workspace/Solution/ProjectId.cs b/Src/Workspaces/Core/Workspace/Solution/ProjectId.cs index 25d669a3f9d..031ca874280 100644 --- a/Src/Workspaces/Core/Workspace/Solution/ProjectId.cs +++ b/Src/Workspaces/Core/Workspace/Solution/ProjectId.cs @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis /// /// An identifier that can be used to refer to the same Project across versions. /// - [DebuggerDisplay("{DebuggerText}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] [Serializable] public class ProjectId : IEquatable { @@ -43,14 +43,14 @@ public static ProjectId CreateNewId(string debugName = null) return new ProjectId(debugName); } - private string DebuggerText + private string GetDebuggerDisplay() { - get { return string.Format("({0}, #{1} - {2})", this.GetType().Name, this.Id, this.debugName); } + return string.Format("({0}, #{1} - {2})", this.GetType().Name, this.Id, this.debugName); } public override string ToString() { - return DebuggerText; + return GetDebuggerDisplay(); } public override bool Equals(object obj) diff --git a/Src/Workspaces/Core/Workspace/Solution/ProjectReference.cs b/Src/Workspaces/Core/Workspace/Solution/ProjectReference.cs index 168a8e8fbdb..8cd3d612cf6 100644 --- a/Src/Workspaces/Core/Workspace/Solution/ProjectReference.cs +++ b/Src/Workspaces/Core/Workspace/Solution/ProjectReference.cs @@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis { [Serializable] - [DebuggerDisplay("{DebuggerDisplay,nq}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] public sealed class ProjectReference : IEquatable { private readonly ProjectId projectId; @@ -62,13 +62,9 @@ public override int GetHashCode() return Hash.CombineValues(aliases, Hash.Combine(projectId, embedInteropTypes.GetHashCode())); } - [DebuggerBrowsable(DebuggerBrowsableState.Never)] - private string DebuggerDisplay + private string GetDebuggerDisplay() { - get - { - return this.projectId.ToString(); - } + return this.projectId.ToString(); } } } diff --git a/Src/Workspaces/Core/Workspace/Solution/SolutionId.cs b/Src/Workspaces/Core/Workspace/Solution/SolutionId.cs index d670f595796..cee9ac0f766 100644 --- a/Src/Workspaces/Core/Workspace/Solution/SolutionId.cs +++ b/Src/Workspaces/Core/Workspace/Solution/SolutionId.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis /// /// An identifier that can be used to refer to the same Solution across versions. /// - [DebuggerDisplay("{DebuggerText}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] [Serializable] public class SolutionId : IEquatable { @@ -39,9 +39,9 @@ public static SolutionId CreateNewId(string debugName = null) return new SolutionId(debugName); } - private string DebuggerText + private string GetDebuggerDisplay() { - get { return string.Format("({0}, #{1} - {2})", GetType().Name, this.Id, this.debugName); } + return string.Format("({0}, #{1} - {2})", GetType().Name, this.Id, this.debugName); } public override bool Equals(object obj) diff --git a/Src/Workspaces/Core/Workspace/WorkspaceDiagnostic.cs b/Src/Workspaces/Core/Workspace/WorkspaceDiagnostic.cs index c1666e08bdd..287e8775891 100644 --- a/Src/Workspaces/Core/Workspace/WorkspaceDiagnostic.cs +++ b/Src/Workspaces/Core/Workspace/WorkspaceDiagnostic.cs @@ -4,7 +4,7 @@ namespace Microsoft.CodeAnalysis { - [DebuggerDisplay("{DebuggerText,nq}")] + [DebuggerDisplay("{GetDebuggerDisplay(),nq}")] public abstract class WorkspaceDiagnostic { public WorkspaceDiagnosticKind Kind { get; private set; } @@ -18,15 +18,13 @@ public WorkspaceDiagnostic(WorkspaceDiagnosticKind kind, string message) public override string ToString() { - return DebuggerText; + return GetDebuggerDisplay(); } - internal string DebuggerText + /// Internal for testing purposes + internal string GetDebuggerDisplay() { - get - { - return string.Format("[{0}] {1}", this.Kind.ToString(), this.Message); - } + return string.Format("[{0}] {1}", this.Kind.ToString(), this.Message); } } } \ No newline at end of file diff --git a/Src/Workspaces/CoreTest/ReferencedSymbolTests.cs b/Src/Workspaces/CoreTest/ReferencedSymbolTests.cs index f14f818c5f7..3fefe75e3fd 100644 --- a/Src/Workspaces/CoreTest/ReferencedSymbolTests.cs +++ b/Src/Workspaces/CoreTest/ReferencedSymbolTests.cs @@ -19,7 +19,7 @@ public void DebuggerDisplay_OneReference() { ReferencedSymbol referencedSymbol = CreateReferencedSymbol("Foo", 1); - Assert.Equal("Foo, 1 ref", referencedSymbol.DebuggerDisplay); + Assert.Equal("Foo, 1 ref", referencedSymbol.GetDebuggerDisplay()); } [Fact, Trait(Traits.Feature, Traits.Features.FindReferences)] @@ -27,7 +27,7 @@ public void DebuggerDisplay_NoReferences() { ReferencedSymbol referencedSymbol = CreateReferencedSymbol("Foo", 0); - Assert.Equal("Foo, 0 refs", referencedSymbol.DebuggerDisplay); + Assert.Equal("Foo, 0 refs", referencedSymbol.GetDebuggerDisplay()); } [Fact, Trait(Traits.Feature, Traits.Features.FindReferences)] @@ -35,7 +35,7 @@ public void DebuggerDisplay_TwoReferences() { ReferencedSymbol referencedSymbol = CreateReferencedSymbol("Foo", 2); - Assert.Equal("Foo, 2 refs", referencedSymbol.DebuggerDisplay); + Assert.Equal("Foo, 2 refs", referencedSymbol.GetDebuggerDisplay()); } private static ReferencedSymbol CreateReferencedSymbol(string symbolName, int referenceCount) diff --git a/Src/Workspaces/CoreTest/SolutionTests.cs b/Src/Workspaces/CoreTest/SolutionTests.cs index f1f7beb378a..d3ec3854a14 100644 --- a/Src/Workspaces/CoreTest/SolutionTests.cs +++ b/Src/Workspaces/CoreTest/SolutionTests.cs @@ -1266,7 +1266,7 @@ public void TestWorkspaceDiagnosticHasDebuggerText() Assert.NotNull(diagnostic); var dd = diagnostic as DocumentDiagnostic; Assert.NotNull(dd); - Assert.Equal(dd.DebuggerText, string.Format("[{0}] {1}", dd.Kind.ToString(), dd.Message)); + Assert.Equal(dd.GetDebuggerDisplay(), string.Format("[{0}] {1}", dd.Kind.ToString(), dd.Message)); } private bool WaitFor(Func condition, TimeSpan timeout) -- GitLab