The blog has moved to a new address. The blog is now located at http://devintelligence.com

Tuesday, May 23, 2006

DebuggerDisplayAttribute

The DebuggerDisplay attribute (System.Diagnostics.DebuggerDisplayAttribute) controls how a class or field is displayed in the debugger variable windows. This attribute can be applied to:

  • Classes
  • Structs
  • Delegates
  • Enums
  • Fields
  • Interfaces
  • Properties
  • Assemblies

The following code example shows how to use DebuggerDisplay


namespace ConsoleApplication11

{

[DebuggerDisplay("OnlineResource: {_Url} {_Port}.")]

public class OnlineResource

{

public string _Url;

public int _Port;



public OnlineResource(string url,int port)

{

this.Url = url;

this.Port = port;

}



public string Url

{

get

{

return _Url;

}

set

{

_Url = value;

}

}


public int Port

{

get

{

return _Port;

}

set

{

_Port = value;

}

}

}

}

2 comments:

Losing Side said...

Here's the real question, how can I access this value programatically? I'd like to be able to use the debugger display values within assertions in Nunit.

Taras said...

I guess you can access it using Reflection API .