Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:18:41+00:00 2026-06-11T13:18:41+00:00

Question: I’m looking for a way to simplify the construction of debugger type proxies

  • 0

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:

  1. NewA‘s type proxy inherits from that of A. Properties don’t show side-by-side; base properties are umbrella’d [sic] under Base. *****
  2. Including an A property in NewA that just casts the current NewA to A, 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:

enter image description here

… 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:

enter image description here


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):

enter image description here

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:

enter image description here

Still doesn’t work. Base properties are not placed side-by-side with the new properties.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:18:43+00:00Added an answer on June 11, 2026 at 1:18 pm

    After hours of searching and tinkering, I found the solution – and a beautiful one at that – from Jared Par’s blog. He creates a type proxy that uses reflection to condense all the members into one list. Some additional DebuggerDisplay magic makes it so you don’t even notice.

    // http://blogs.msdn.com/b/jaredpar/archive/2010/02/19/flattening-class-hierarchies-when-debugging-c.aspx
    // by Jared Par
    internal sealed class FlattenHierarchyProxy {
    
        [DebuggerDisplay("{Value}", Name = "{Name,nq}", Type = "{Type.ToString(),nq}")]
        internal struct Member {
            internal string Name;
            internal object Value;
            internal Type Type;
            internal Member(string name, object value, Type type) {
                Name = name;
                Value = value;
                Type = type;
            }
        }
    
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private readonly object _target;
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private Member[] _memberList;
    
        [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
        internal Member[] Items {
            get {
                if (_memberList == null) {
                    _memberList = BuildMemberList().ToArray();
                }
                return _memberList;
            }
        }
    
        public FlattenHierarchyProxy(object target) {
            _target = target;
        }
    
        private List<Member> BuildMemberList() {
            var list = new List<Member>();
            if ( _target == null ) {
                return list;
            }
    
            var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var type = _target.GetType();
            foreach (var field in type.GetFields(flags)) {
                var value = field.GetValue(_target);
                list.Add(new Member(field.Name, value, field.FieldType));
            }
    
            foreach (var prop in type.GetProperties(flags)) {
                object value = null;
                try {
                    value = prop.GetValue(_target, null);
                }
                catch (Exception ex) {
                    value = ex;
                }
                list.Add(new Member(prop.Name, value, prop.PropertyType));
            }
    
            return list;
        }
    }
    

    Modifications

    I made three little modifications to the class to make it more usable for me.

    First, I wanted the members sorted by name. To do this, change the last line to:

    return list.OrderBy(m => m.Name).ToList();
    

    Second, in the Member struct, I added some attributes so that only the value would show when you expand a reference class:

    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    internal string Name;
    [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
    internal object Value;
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]
    internal Type Type;
    

    Third, the default flags BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance mean that even members marked [DebuggerBrowsable(DebuggerBrowsableState.Never)] will still be shown. To prevent this from happening, after this line:

    foreach (var field in type.GetFields(flags)) {
    

    add this:

    // Respect DebuggerBrowsableAttributes
    var debuggerBrowsableAtts = field.GetCustomAttributes(typeof(DebuggerBrowsableAttribute), true);
    if (debuggerBrowsableAtts.Count() == 1) {
        var att = debuggerBrowsableAtts[0] as DebuggerBrowsableAttribute;
        if (att.State == DebuggerBrowsableState.Never) {
            continue;
        }
    }
    

    Now the DebuggerBrowsable(DebuggerBrowsableState.Never) will be respected for fields. You can also add that code the foreach loop that handles properties, to have it respected for properties as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: Why is it that holdDate under function Check(), show Nothing while debugging, I
Question Is it possible to stop a Message Driven Bean (programmatically), so that it
Question context: let say that there is some really important row in config/locales/en.yml that
Question: Can I override default functions in Javascript? Background: After figuring out that I
Question: Upon click, I see that evt.target.attributes stores all of the attributes in an
Question Is it possible to create a second Preference Dialog that can take some
Question Does anyone know of a way to round a float to the nearest
Question: input an int number ex: ABCD, verify that is ABCD = AB*CD or
Question : Is there a simple way to print out an array in Ruby
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.