次の方法で共有


DebuggerDisplayAttribute Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Determines how a class or field is displayed in the debugger variable windows.

Inheritance Hierarchy

System.Object
  System.Attribute
    System.Diagnostics.DebuggerDisplayAttribute

Namespace:  System.Diagnostics
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Enum Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Delegate, AllowMultiple := True)> _
Public NotInheritable Class DebuggerDisplayAttribute _
    Inherits Attribute
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Delegate, AllowMultiple = true)]
public sealed class DebuggerDisplayAttribute : Attribute

The DebuggerDisplayAttribute type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 DebuggerDisplayAttribute Initializes a new instance of the DebuggerDisplayAttribute class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Name Gets or sets the name to display in the debugger variable windows.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Target Gets or sets the type of the attribute's target.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 TargetTypeName Gets or sets the type name of the attribute's target.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Type Gets or sets the string to display in the type column of the debugger variable windows.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Value Gets the string to display in the value column of the debugger variable windows.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

NoteNote:

The common language runtime attaches no semantics to this attribute. It is provided for use by source code debuggers.

The DebuggerDisplayAttribute constructor has a single argument: a string to be displayed in the value column for instances of the type. This string can contain braces ({ and }). The text within a pair of braces is evaluated as the name of a field, property, or method. For example, the following C# code causes "Count = 4" to be displayed when the plus sign (+) is clicked to expand the debugger display for an instance of MyHashtable.

[DebuggerDisplay("Count = {count}")]
class MyHashtable
{
    public int count = 4;
}

Attributes that are applied to properties referenced in the expression are not processed. For some compilers, a general expression may be allowed that has only implicit access to this reference for the current instance of the target type. The expression is limited; there is no access to aliases, locals, or pointers.

This attribute can be applied to the following:

  • Classes

  • Structures

  • Delegates

  • Enumerations

  • Fields

  • Properties

  • Assemblies

The Target property specifies the target type when the attribute is used at the assembly level. The Name property can contain a string similar to the one used in the constructor, with expressions enclosed in braces. The Type property can be set blank if the type should not be displayed in the data windows.

NoteNote:

The properties should be used only on type proxies.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference