提交 46485bb3 编写于 作者: P Pilchie

Make our use of DebuggerDisplayAttribute more consistent (changeset 1234216)

上级 006e5f1b
......@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols
/// <summary>
/// Information about a reference to a symbol.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
public struct ReferenceLocation : IComparable<ReferenceLocation>, IEquatable<ReferenceLocation>
{
/// <summary>
......@@ -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
......@@ -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).
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
public class ReferencedSymbol
{
/// <summary>
......@@ -34,14 +34,11 @@ internal ReferencedSymbol(ISymbol definition, IEnumerable<ReferenceLocation> loc
this.Locations = (locations ?? SpecializedCollections.EmptyEnumerable<ReferenceLocation>()).ToReadOnlyCollection();
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
internal string DebuggerDisplay
/// <remarks>Internal for testing purposes</remarks>
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");
}
}
}
......@@ -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.
/// </summary>
[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
......@@ -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.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
public partial class Document
{
private readonly DocumentState state;
......@@ -470,13 +470,9 @@ internal async Task<Document> WithFrozenPartialSemanticsAsync(CancellationToken
}
}
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay
private string GetDebuggerDisplay()
{
get
{
return this.Name;
}
return this.Name;
}
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis
/// An identifier that can be used to retrieve the same Document across versions of the
/// workspace.
/// </summary>
[DebuggerDisplay("{DebuggerText}")]
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
[Serializable]
public class DocumentId : IEquatable<DocumentId>
{
......@@ -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)
......
......@@ -121,7 +121,7 @@ private static async Task<TextAndVersion> 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());
}
}
......
......@@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis
/// <summary>
/// Represents a project that is part of a solution.
/// </summary>
[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
......@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis
/// <summary>
/// An identifier that can be used to refer to the same Project across versions.
/// </summary>
[DebuggerDisplay("{DebuggerText}")]
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
[Serializable]
public class ProjectId : IEquatable<ProjectId>
{
......@@ -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)
......
......@@ -10,7 +10,7 @@
namespace Microsoft.CodeAnalysis
{
[Serializable]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
public sealed class ProjectReference : IEquatable<ProjectReference>
{
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();
}
}
}
......@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis
/// <summary>
/// An identifier that can be used to refer to the same Solution across versions.
/// </summary>
[DebuggerDisplay("{DebuggerText}")]
[DebuggerDisplay("{GetDebuggerDisplay(),nq}")]
[Serializable]
public class SolutionId : IEquatable<SolutionId>
{
......@@ -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)
......
......@@ -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
/// <remarks>Internal for testing purposes</remarks>
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
......@@ -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)
......
......@@ -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<bool> condition, TimeSpan timeout)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册