DebuggerTypeProxyAttribute

The DebuggerTypeProxyAttribute type assigns a display proxy for another type. The type proxy is displayed instead of the actual type in debug windows. The DebuggerTypeProxyAttribute is an attribute that is valid for assembly, class, and struct constructs. When used at the assembly level, the target name property identifies the target type.

The proxy type must have a one-argument constructor that accepts an instance of the underlying type. For this reason, it is recommended that the proxy type be nested within the target type. This provides the proxy type constructor easy access to the instance of the surrounding object. Only public members of the proxy are visible in the debug window.

The DebuggerTypeProxyAttribute type is useful for hiding sensitive data from users. In the following code, XClass has a password field. This field should not be exposed during debugging because passwords are sensitive data. The DebuggerTypeProxyAttribute type in the sample code names XClassDebug as the proxy. XClassDebug hides the password field and displays an appropriate alternative value of "Not Available".

Here is the code for XClass and the nested XClassDebug class, which is the proxy class:

[DebuggerTypeProxy(typeof(XClassDebug))]
public class XClass
{
    public XClass(string _password)
    {
        password = _password;
    }
    private string password;
    internal class XClassDebug
    {
        public XClassDebug(XClass obj)
        {
        }

        public string password = "Not Available";
    }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.97.126