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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > 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) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DebuggerDisplayAttribute クラス」の関連用語

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

   

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



DebuggerDisplayAttribute クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS