DebuggerDisplayAttributeとは? わかりやすく解説

DebuggerDisplayAttribute クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

デバッガ変数ウィンドウ内でクラスまたはフィールドを表示する方法を決定します。

名前空間: System.Diagnostics
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class
 Or AttributeTargets.Struct Or AttributeTargets.Enum
 Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Delegate, AllowMultiple:=True)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 DebuggerDisplayAttribute
    Inherits Attribute
Dim instance As DebuggerDisplayAttribute
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Delegate,
 AllowMultiple=true)] 
[ComVisibleAttribute(true)] 
public sealed class DebuggerDisplayAttribute
 : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Enum|AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Delegate,
 AllowMultiple=true)] 
[ComVisibleAttribute(true)] 
public ref class DebuggerDisplayAttribute sealed
 : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Delegate,
 AllowMultiple=true) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DebuggerDisplayAttribute
 extends Attribute
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Delegate,
 AllowMultiple=true) 
ComVisibleAttribute(true) 
public final class DebuggerDisplayAttribute
 extends Attribute
解説解説

DebuggerDisplayAttribute コンストラクタは、1 つの引数 (型のインスタンスの値列に表示される文字列) を持っています。この文字列には、中かっこ ({ と }) が含まれます。中かっこに囲まれたテキストは、フィールド、プロパティ、またはメソッドの名前と見なされます。たとえば、次の C# コードでは、正符号 (+) を選択して MyHashtable のインスタンスのデバッガ表示を展開すると、"Count = 4" が表示されます。

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

式で参照されるプロパティに適用する属性は処理されません。コンパイラによっては、対象の型の現在のインスタンスに対して、この参照への暗黙的なアクセスだけを持つ、一般的な式を使用できる場合があります。式には、エイリアス、ローカル、またはポインタへのアクセスを含めないという制限があります。

この属性の適用対象は次のとおりです。

Target プロパティは、属性がアセンブリ レベルで使用される場合の対象の型を指定します。Name プロパティには、コンストラクタで使用される文字列のような文字列を中かっこで囲んだ式で含めることができます。型をデータ ウィンドウで表示しない場合は、Type プロパティを空白にすることができます。

メモメモ

プロパティは、型プロキシでのみ使用してください。

この属性の Visual Studio 2005 での使用の詳細については、「DebuggerDisplay 属性の使用」を参照してください。

使用例使用例

次のコード例を Visual Studio 2005 で参照して、DebuggerDisplayAttribute を適用した結果を確認できます。

using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
//[assembly: DebuggerTypeProxy("MyHashtable.HashtableDebugView"
,TargetTypeName="MyHashtable")]
class DebugViewTest
{
    // The following constant will appear in the debug window for DebugViewTest.
    const string TabString = "    ";
    // The following DebuggerBrowsableAttribute prevents the property
 following it 
    // from appearing in the debug window for the class.
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    public static string
 y = "Test String";

    static void Main(string[]
 args)
    {
        MyHashtable myHashTable = new MyHashtable();
        myHashTable.Add("one", 1);
        myHashTable.Add("two", 2);
        Console.WriteLine(myHashTable.ToString());
        Console.WriteLine("In Main.");

 }
}
[DebuggerDisplay("{value}", Name = "{key}")]
internal class KeyValuePairs
{
    private IDictionary dictionary;
    private object key;
    private object value;

    public KeyValuePairs(IDictionary dictionary, object key, object
 value)
    {
        this.value = value;
        this.key = key;
        this.dictionary = dictionary;
    }
}
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(HashtableDebugView))]
class MyHashtable : Hashtable
{
    private const string
 TestString = "This should not appear in the debug window.";

    internal class HashtableDebugView
   {
      private Hashtable hashtable;
      public const string
 TestString = "This should appear in the debug window.";
      public HashtableDebugView(Hashtable hashtable)
      {
         this.hashtable = hashtable;
      }

      [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
      public KeyValuePairs[] Keys
      {
         get 
         {
             KeyValuePairs[] keys = new KeyValuePairs[hashtable.Count];

            int i = 0;
            foreach(object key in hashtable.Keys)
            {
               keys[i] = new KeyValuePairs(hashtable, key, hashtable[key]);
               i++;
            }
         return keys;
         }
      }
   }
}
継承階層継承階層
System.Object
   System.Attribute
    System.Diagnostics.DebuggerDisplayAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DebuggerDisplayAttribute コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

DebuggerDisplayAttribute クラスの新しいインスタンスを初期化します。

名前空間: System.Diagnostics
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim value As String

Dim instance As New DebuggerDisplayAttribute(value)
public DebuggerDisplayAttribute (
    string value
)
public:
DebuggerDisplayAttribute (
    String^ value
)
public DebuggerDisplayAttribute (
    String value
)
public function DebuggerDisplayAttribute (
    value : String
)

パラメータ

value

型のインスタンスの値列に表示される文字列。null 参照 (Visual Basic では Nothing) は空の文字列 ("") と同等です。

解説解説
使用例使用例

次のコード例では、正符号 (+) を選択して MyHashtable のインスタンスのデバッガ表示を展開すると、継承された Hashtable クラスからの Count プロパティの値が表示されます。結果を確認するには、DebuggerDisplayAttribute クラスのトピックで取り上げているコード例全体を実行する必要があります。

[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(HashtableDebugView))]
class MyHashtable : Hashtable
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DebuggerDisplayAttribute クラス
DebuggerDisplayAttribute メンバ
System.Diagnostics 名前空間

DebuggerDisplayAttribute プロパティ


DebuggerDisplayAttribute メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
参照参照

関連項目

DebuggerDisplayAttribute クラス
System.Diagnostics 名前空間

DebuggerDisplayAttribute メンバ

デバッガ変数ウィンドウ内でクラスまたはフィールドを表示する方法を決定します。

DebuggerDisplayAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DebuggerDisplayAttribute DebuggerDisplayAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
参照参照

関連項目

DebuggerDisplayAttribute クラス
System.Diagnostics 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DebuggerDisplayAttribute」の関連用語

DebuggerDisplayAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DebuggerDisplayAttributeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS