3

Is it possible to call a method with parameter(s) within the DebuggerDisplay attribute? I did not find helpful information for this problem in the MSDN article Using the DebuggerDisplay Attribute.

I try to call the ToString method with a string parameter "d"; but the following did not work:

[DebuggerDisplay(@"{ToString(""d"")}")]
public class ...

I know it is recommended to use a private property instead of complex expressions. But is it nevertheless possible with an expression?

Koopakiller
  • 2,838
  • 3
  • 32
  • 47
  • Which version of Visual Studio? This works fine for me, sort of. If I mouse over a local it shows the DebuggerDisplay attribute, but in the locals/watch windows it shows ToString(). What is shown in locals/watch is controlled by the user setting in Tools > Options > Debugging, "Show raw structure of objects in variables windows" option. If this is checked, you always get ToString and DebuggerDisplay is ignored there. – Mike Zboray Jan 23 '16 at 00:00
  • @mikez I use VS 2015 Enterprise, all updates are installed. I tried it on a VM and there it works well too, but on my primary environment it always ignore the attribute. – Koopakiller Jan 23 '16 at 00:13

1 Answers1

3

I don't think it will allow that. But why cant you do this:

[DebuggerDisplay(@"{DebugDisplay}")]
public class ...

private string DebugDisplay
{
    get
    {
        return ToString("d");
    }
}
Cleverguy25
  • 493
  • 3
  • 14
  • It is more a theoretical question. I implemented already a property like you suggested. But I am not sure if it is possible to call a method with parameters or not. – Koopakiller Jan 22 '16 at 23:40