4

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?

2
  • 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. Commented Jan 23, 2016 at 0: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. Commented Jan 23, 2016 at 0:13

1 Answer 1

4

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");
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.