DebuggerDisplay属性不起作用

DebuggerDisplay属性不起作用

问题描述:

这是一个针对.NET 2.0框架的C++/CLI WinForms项目。我正在使用Visual Studio 2008.如何使它工作?DebuggerDisplay属性不起作用

编辑:代码片断

[Serializable] 
[DebuggerDisplayAttribute(L"ID={EmployeeID}")] 
public ref class Employee 
{ 
    [ReadOnly(true)] 
    int nID; 
    property int EmployeeID 
    { 
     int get() 
     { 
      return nID; 
     } 
    } 
} 
+0

代码片段?什么是失败? – Brian 2009-02-26 11:00:09

+0

它不会像往常一样显示自定义文本: “employee = 0x058482f8 {age = 46 tracker = 0x0584f1cc nID = 14 ...}” – 2009-02-26 11:19:13

共识是C++ IDE不支持它。

定义“不工作” ......它肯定在C#中工作(我不知道如果C++编辑器支持它 - 只是翻译其下面在C#工程找出;-p)

using System.Diagnostics; 
[DebuggerDisplay("HiWorld={Bar}")] 
class Foo 
{ 
    public string Bar { get; set; } 
    static void Main() 
    { 
     Foo foo = new Foo { Bar = "abc" }; 
     // breakpoint and hover shows: HiWorld="abc" 
    } 
} 

我不 “做” C++了,而是反射说:

[DebuggerDisplay(S"HiWorld={Bar}")] 
private __gc class Foo 
{ 
    // Methods 
    private: static void __gc* Main() 
    { 
     Foo __gc* <>g__initLocal0 = __gc new Foo(); 
     <>g__initLocal0->Bar = S"abc"; 
     Foo __gc* foo = <>g__initLocal0; 
    } 


    // Properties 
    [CompilerGenerated] 
    public: __property String __gc* get_Bar() 
    { 
     return this-><Bar>k__BackingField; 
    } 
    [CompilerGenerated] 
    public: __property void __gc* set_Bar(String __gc* value) 
    { 
     this-><Bar>k__BackingField = value; 
    } 


    // Fields 
    [CompilerGenerated] 
    private: String __gc* <Bar>k__BackingField; 
}; 

我认为你的问题可能是你指定了宽字符串(L"ID={EmployeeID}")而不是CLR字符串(S"ID={EmployeeID}")。所以也许把L改为S,看看你怎么走?