Reputation: 2433
In particular, examining a Windows Form object, I want to see the members defined in my code without always seeing the hundreds of members defined by the framework in the base class.
Upvotes: 2
Views: 170
Reputation: 5105
There are multiple inbuilt ways using Framework Attributes (though none of which particularly scalable).
[DebuggerDisplay]
Assume your class looks like this:
public class MyForm : Form
{
public int Foo { get; set; }
public string Bar { get; set; }
}
you can add the [DebuggerDisplayAttribute]
to the class like this:
[DebuggerDisplay("Foo = {Foo}, Bar = {Bar}")
public class MyForm : Form
{
public int Foo { get; set; }
public string Bar { get; set; }
}
which now only shows Foo
and Bar
.
Advantage: displays only those members you wish to.
Disadvantage: you have to explicitly specify the members to display, and repeat that step for every property you add later.
[DebuggerTypeProxy]
You can define a proxy class that should be shown in the debugger instead of your real class.
Again, assuming that your class looks like this
public class MyForm : Form
{
public int Foo { get; set; }
public string Bar { get; set; }
}
you can now go ahead and define a proxy class that exposes only those members that you want to display and apply the [DebuggerTypeProxyAttribute]
to the class like this:
[DebuggerTypeProxy(typeof(MyFormDebugView))]
public class MyForm : Form
{
public int Foo { get; set; }
public string Bar { get; set; }
}
public class MyFormDebugView
{
public int Foo { get; set; }
public string Bar { get; set; }
}
Now you will only see Foo
and Bar
in the debugger display, not the inherited members of Form
.
Advantage: displays only the members in the proxy class. No need to specify those members explicitly.
Disadvantage: you have to adjust the proxy type whenever you add a new property etc. to your MyForm
that should be seen in the debugger.
Upvotes: 5