kalyfe
kalyfe

Reputation: 1005

Hiding fields listed twice from debugger window

When inspecting the Response of a Webservice in the debugger window, every field of the response is listed twice - once with an appendix of Field.


(source: mlkshk.com)

How can I hide the second listing?

The webservice reference is added as outlined on the msdn library, so I don't want to add the attribute [DebuggerBrowsable(DebuggerBrowsableState.Never)] manually.

Upvotes: 1

Views: 168

Answers (1)

Anssssss
Anssssss

Reputation: 3262

This is a bit of a hack, and isn't as presentable as the regular Watch window would be, but you could use this process.

  1. Add a GetFieldValues utility method that would extract just the field values you want.
  2. While debugging, open the Immediate Window
  3. In the Immediate Window, create a variable that captures the results of GetFieldValues
  4. In the Watch window, add that newly created variable.

That way you can filter out the stuff you don't want to see. Here's a screenshot of it in action: Visual Studio immediate and watch windows

Utility method:

public static List<Tuple<String,Object>> GetFieldValues(Object instance)
{
    var fields = instance.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
    var fieldValues = new List<Tuple<String, Object>>();
    foreach (var f in fields) { fieldValues.Add(new Tuple<string, Object>(f.Name, f.GetValue(instance))); }
    return fieldValues;
}

And the Immediate Window code:

var blah = J.GetFieldValues(this);

Upvotes: 1

Related Questions