Wiki
Clone wikiBaseMemberPromotingProxy / Home
Introduction
BaseMemberPromotingProxy
is a (terribly named) class meant to be used as the target for the DebuggerTypeProxy
attribute. The code is based off of Jared Parsons’ FlattenHierarchyProxy
. Like the original, BaseMemberPromotingProxy (which will be referred to as BMPP throughout the rest of this documentation) is designed to improve the debugger displays of classes that inherit from other classes.
What is this?
For the sake of not duplicating content (read: I'm lazy), I describe what this is, as well as the motivation behind it, on my blog. This page is just meant to be documentation.
Installation
There is only a single source file, BaseMemberPromotingProxy.cs
, so it's up to you whether you want to plop that file into your project or build a DLL from the source file. Either way, you'll need to import my namespace:
using MostThingsWeb;
Usage
Basic usage
The simplest way to use BMPP is to just apply this attribute to your class:
[DebuggerTypeProxy(typeof(BaseMemberPromotingProxy))]
public class ParentClass : SubClass {}
Now, properties and fields from sub classes will appear side-by-side (be "promoted") with the members of the parent class.
Advanced usage
Let's say you don't want to promote every member from the subclasses; just specific ones. To do this, use the PromoteProperty
or PromoteField
attributes.
These attributes take a single parameter, the name of the property or field to promote. The name of the member is case sensitive.
Use of one or more PromoteProperty
s disables automatic promotion for all other subclass properties. In other words, BMPP is switched into "opt-in" mode for properties. So, if you use a PromoteProperty
attribute to promote a specific property, only that property and the properties of the parent ("target") class will appear in the debugger display.
PromoteField
exhibits the same exact behavior, but for fields instead of properties.
To illustrate these attributes, consider this example:
public class Poultry {
// Fields
private int _weight;
// Properties
public bool Delicious {
get { return true; }
}
public int Weight { /* get/set backing field _weight */ }
}
[DebuggerTypeProxy(typeof(BaseMemberPromotingProxy))]
// !!! Attributes from table below go here !!!
public class Chicken : Poultry {
// Fields
private bool _hen = true;
// Properties
public String Sound {
get { return "Cluck"; }
}
}
Let's consider what happens when different combinations of PromoteProperty
and PromoteField
attributes are applied to the Chicken
class, in addition to the DebuggerTypeProxy
, which is always necessary. X
denotes the members that the debugger display will show.
Attributes | _hen | Sound | _weight | Delicious | Weight |
---|---|---|---|---|---|
(none) | X | X | X | X | X |
[PromoteProperty("Delicious")] | X | X | X | X | |
[PromoteProperty("Weight")] | X | X | X | X | |
[PromoteProperty("Weight"), PromoteProperty("Delicious")] | X | X | X | X | X |
[PromoteProperty("FicticiousProperty") | X | X | X | ||
[PromoteField("_weight") | X | X | X | X | X |
[PromoteField("_ficticiousField") | X | X | X | X |
Here's what you should take away from this chart:
- No matter what you do, parent (where the
BaseMemberPromoteProperty
attribute is applied to) members are always shown - The
PromoteProperty
attribute switches BMPP into "opt-in" mode for properties. - The
PromoteField
attribute switches BMPP into "opt-in" mode for fields. PromoteProperty
has no effect on fields, nor doesPromoteField
have any effect on properties.- Specifying non-existent members has no effect, other than to switch on "opt-in" mode for that member type.
Future improvements
Please comment on my blog or submit a BitBucket issue if any of the following interest you:
- An "opt-out" mode
- Different sort behavior on debugger displays (for example, separately sorting fields and properties)
License
This project is licensed under an MIT license. Please see licenses text in the main source file, BaseMemberPromotingProxy.cs
.
Updated