debuggerdisplay

Possible to accessing child “DebuggerDisplay” attribute of property?

一世执手 提交于 2020-01-02 01:21:09
问题 Current state Having two classes: [DebuggerDisplay(@"One = {One}, two = {Two}")] public class A { public int One { get; set; } public B Two { get; set; } } [DebuggerDisplay(@"Three = {Three}")] public class B { public int Three { get; set; } } Using them: var a = new A {One = 5, Two = new B {Three = 10}}; Inside the debugger, the tool tip value that is displayed at a is One = 5, two = {DebuggerDisplayTest.B} Goal What I would want is something like One = 5, two = 'Three = 10' I know this

Chaining DebuggerDisplay on complex types

大憨熊 提交于 2019-12-18 07:35:01
问题 I have several classes defining the DebuggerDisplay attribute. I want to know if there is a way to define one DebuggerDisplay attribute based on another one. If I have the following classes: [DebuggerDisplay ("Text = {Text}")] class A { public string Text {get;set;} } [DebuggerDisplay ("Property = {Property}")] class B { public A Property {get; set;} } I would like to see on instances of B the A class as it is defined on the class A DebuggerDisplay attribute. Instead of that I'm getting the

Chaining DebuggerDisplay on complex types

感情迁移 提交于 2019-12-18 07:33:47
问题 I have several classes defining the DebuggerDisplay attribute. I want to know if there is a way to define one DebuggerDisplay attribute based on another one. If I have the following classes: [DebuggerDisplay ("Text = {Text}")] class A { public string Text {get;set;} } [DebuggerDisplay ("Property = {Property}")] class B { public A Property {get; set;} } I would like to see on instances of B the A class as it is defined on the class A DebuggerDisplay attribute. Instead of that I'm getting the

Does there exists a method to render an object using DebuggerDisplayAttribute

痴心易碎 提交于 2019-12-07 02:31:55
问题 I have a number of classes that are decorated with DebuggerDisplayAttribute. I want to be able to add trace statements to Unit Tests that will display instances of these classes. Does there exist a method in the .NET Framework that will display an object formatted using DebuggerDisplayAttribute (or fall back to using .ToString() if no DebuggerDisplayAttribute is defined)? EDIT To clarify, I was hoping there might be something built into the Framework. I know I can get the Value property from

Possible to accessing child “DebuggerDisplay” attribute of property?

随声附和 提交于 2019-12-05 03:36:00
Current state Having two classes: [DebuggerDisplay(@"One = {One}, two = {Two}")] public class A { public int One { get; set; } public B Two { get; set; } } [DebuggerDisplay(@"Three = {Three}")] public class B { public int Three { get; set; } } Using them: var a = new A {One = 5, Two = new B {Three = 10}}; Inside the debugger, the tool tip value that is displayed at a is One = 5, two = {DebuggerDisplayTest.B} Goal What I would want is something like One = 5, two = 'Three = 10' I know this could be achieved by overriding the ToString() method of class B . This just feels not right, since I'm

Is it possible to use conditions in a DebuggerDisplay?

牧云@^-^@ 提交于 2019-12-04 16:45:41
问题 Consider the following class: [DebuggerDisplay("{GetType().Name,nq}: FileName = {FileName,nq}")] public class FileWrapper { public string FileName { get; set; } public bool IsTempFile { get; set; } public string TempFileName { get; set; } } I would like to add a debugger display based on the IsTempFileName property. I would like to add the string , TempFileName = {TempFileName,nq} when the instance is a temp file. How would I achieve something this? 回答1: You can use the conditional operator (

Is it possible to use conditions in a DebuggerDisplay?

試著忘記壹切 提交于 2019-12-03 09:53:56
Consider the following class: [DebuggerDisplay("{GetType().Name,nq}: FileName = {FileName,nq}")] public class FileWrapper { public string FileName { get; set; } public bool IsTempFile { get; set; } public string TempFileName { get; set; } } I would like to add a debugger display based on the IsTempFileName property. I would like to add the string , TempFileName = {TempFileName,nq} when the instance is a temp file. How would I achieve something this? You can use the conditional operator (?:) [DebuggerDisplay("{GetType().Name,nq}: FileName = {FileName,nq}{IsTempFile ? \", TempFileName: \" +

C# debugging: [DebuggerDisplay] or ToString()?

烂漫一生 提交于 2019-12-03 04:00:39
问题 There are two ways to increase the usefulness of debugging information instead of seeing {MyNamespace.MyProject.MyClass} in the debugger. These are the use of the [DebuggerDisplayAttribute][1] and the ToString() method. using System.Diagnostics; ... [DebuggerDisplay("Name = {Name}")] public class Person { public string Name; } or public class Person { public string Name; public override string ToString() { return string.Format("Name = {0}", Name); } } Is there any reason to prefer one to the

C# debugging: [DebuggerDisplay] or ToString()?

[亡魂溺海] 提交于 2019-12-02 17:22:23
There are two ways to increase the usefulness of debugging information instead of seeing {MyNamespace.MyProject.MyClass} in the debugger. These are the use of the [DebuggerDisplayAttribute][1] and the ToString() method. using System.Diagnostics; ... [DebuggerDisplay("Name = {Name}")] public class Person { public string Name; } or public class Person { public string Name; public override string ToString() { return string.Format("Name = {0}", Name); } } Is there any reason to prefer one to the other? Any reason not to do both? Is it purely personal preference? Using [DebuggerDisplay] is meant

Chaining DebuggerDisplay on complex types

半世苍凉 提交于 2019-11-29 13:10:49
I have several classes defining the DebuggerDisplay attribute. I want to know if there is a way to define one DebuggerDisplay attribute based on another one. If I have the following classes: [DebuggerDisplay ("Text = {Text}")] class A { public string Text {get;set;} } [DebuggerDisplay ("Property = {Property}")] class B { public A Property {get; set;} } I would like to see on instances of B the A class as it is defined on the class A DebuggerDisplay attribute. Instead of that I'm getting the class A ToString() method onto the debugger while viewing class B objects. Not sure if I understood your