Question: I'm looking for a way to simplify the construction of debugger type proxies for inherited classes. So, when debugging a class that inherits from another, I should see the properties of both side-by-side: the base properties of the base class, plus the new properties of the parent class.
Here's what I've tried so far:
NewA
's type proxy inherits from that ofA
. Properties don't show side-by-side; base properties are umbrella'd [sic] underBase
. *****- Including an
A
property inNewA
that just casts the currentNewA
toA
, with[DebuggerBrowsable(RootHidden)]
: Visual Studio hangs :(
I know that I could just add properties for the base class into NewA
's proxy, but I'm trying to avoid this. It's too much work for classes with many properties.
Explanation:
I'm using the DebuggerTypeProxy
attribute on some of my classes so I can control how the class looks when browsed during debugging. For example:
public class A {
private String _someField;
public String SomeField {
get {return _someField;}
}
}
By default, the tooltip debugging info shows as:
... so I use a DebuggerTypeProxy to hide the backing field:
[DebuggerTypeProxy(typeof(AProxy))]
public class A {
// ...
internal class AProxy {
A _a;
AProxy (A a){
_a = a;
}
public String SomeField {
get {return _a.SomeField;}
}
}
}
... all is right with the world:
Now, I create a class that inherits from A.
public class NewA : A {
private String _anotherField;
public String AnotherField {
get {return _anotherField;}
}
}
Unfortunately, when debugging this class, Visual Studio uses the base type proxy (from A
). This means we can see the base SomeField
property, but our new AnotherField
property is hidden (unless you expand Raw View
, of course):
Removing the type proxy from base A
results in AnotherField
showing, but not SomeField
.
* Failed attempt #1
/// <summary>
/// The base class
/// </summary>
[DebuggerTypeProxy(typeof(AProxy))]
public class A {
private String _someField;
public String SomeField {
get { return _someField; }
}
protected class AProxy {
A _a;
protected AProxy(A a) {
_a = a;
}
String SomeField {
get { return _a.SomeField; }
}
}
}
/// <summary>
/// Parent class
/// </summary>
[DebuggerTypeProxy(typeof(NewAProxy))]
public class NewA : A {
private String _anotherField;
public String AnotherField {
get { return _anotherField; }
}
// Inherit base type proxy, in an effort to display base properties
// side-by-side with AnotherField: Doesn't work.
protected class NewAProxy : A.AProxy {
NewA _newA;
protected NewAProxy(NewA newA)
: base(newA) {
_newA = newA;
}
public String AnotherField {
get { return _newA.AnotherField; }
}
}
}
Result:
Still doesn't work. Base properties are not placed side-by-side with the new properties.