Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I have my DebuggerTypeProxy target class inherit from base proxies?
    primarykey
    data
    text
    <p><strong>Question:</strong> 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.</p> <p>Here's what I've tried so far:</p> <ol> <li><code>NewA</code>'s type proxy inherits from that of <code>A</code>. Properties don't show side-by-side; base properties are umbrella'd [sic] under <code>Base</code>. <sup>*****</sup></li> <li>Including an <code>A</code> property in <code>NewA</code> that just casts the current <code>NewA</code> to <code>A</code>, with <code>[DebuggerBrowsable(RootHidden)]</code>: Visual Studio hangs :( </li> </ol> <p>I know that I could just add properties for the base class into <code>NewA</code>'s proxy, but I'm trying to avoid this. It's too much work for classes with many properties.</p> <hr/> <p><strong>Explanation:</strong></p> <p>I'm using the <code>DebuggerTypeProxy</code> attribute on some of my classes so I can control how the class looks when browsed during debugging. For example:</p> <pre><code>public class A { private String _someField; public String SomeField { get {return _someField;} } } </code></pre> <p>By default, the tooltip debugging info shows as:</p> <p><img src="https://i.stack.imgur.com/1iuJe.png" alt="enter image description here"></p> <p>... so I use a DebuggerTypeProxy to hide the backing field:</p> <pre><code>[DebuggerTypeProxy(typeof(AProxy))] public class A { // ... internal class AProxy { A _a; AProxy (A a){ _a = a; } public String SomeField { get {return _a.SomeField;} } } } </code></pre> <p>... all is right with the world:</p> <p><img src="https://i.stack.imgur.com/TNgYx.png" alt="enter image description here"></p> <hr/> <p>Now, I create a class that inherits from A.</p> <pre><code>public class NewA : A { private String _anotherField; public String AnotherField { get {return _anotherField;} } } </code></pre> <p>Unfortunately, when debugging this class, Visual Studio uses the base type proxy (from <code>A</code>). This means we can see the base <code>SomeField</code> property, but our new <code>AnotherField</code> property is hidden (unless you expand <code>Raw View</code>, of course):</p> <p><img src="https://i.stack.imgur.com/W22tD.png" alt="enter image description here"></p> <p>Removing the type proxy from base <code>A</code> results in <code>AnotherField</code> showing, but not <code>SomeField</code>.</p> <hr/> <p><strong><sup>*</sup> Failed attempt #1</strong></p> <pre><code>/// &lt;summary&gt; /// The base class /// &lt;/summary&gt; [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; } } } } /// &lt;summary&gt; /// Parent class /// &lt;/summary&gt; [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; } } } } </code></pre> <p>Result:</p> <p><img src="https://i.stack.imgur.com/xGGKx.png" alt="enter image description here"></p> <p>Still doesn't work. Base properties are not placed side-by-side with the new properties.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload