gpt4 book ai didi

c# - DebuggerDisplayAttribute - 它如何在评估表达式时选择语言?

转载 作者:太空狗 更新时间:2023-10-30 00:47:07 31 4
gpt4 key购买 nike

http://msdn.microsoft.com/en-us/library/x810d419.aspx

从我们在 MSDN 上看到的内容来看,它说要小心我们放置的表达式,因为它们会随着语言的变化而变化。我的问题是:编写这些表达式支持哪些语言?如果各种语言都可以做到,它如何检测正在使用哪种语言?

我已经在 CLI 中创建了我的类(class),并在 c# 中编写了表达式,因为它可以工作。我在 C++/CLI 中尝试过,但那样不行。

这是我的代码:

[DebuggerDisplay("z = {ToString()} Norm = {System.Math.Round(Norm,2)} Angle = {System.Math.Round(Angle, 2)}")]

现在,尝试使用 C++/CLI 方式:

[DebuggerDisplay("z = {ToString()} Norm = {System::Math::Round(Norm,2)} Angle = {System::Math::Round(Angle, 2)}")]

我的假设是它总是将表达式读取为 C# 代码。这是真的吗?

最佳答案

我找到了这个 link

There is a down-side to this power though - because evaluation of the DebuggerDisplayAttribute format string is compiler-specific, the first example will work fine most other debuggers such as VB, but the second one will not evaluate due to its use of the C#-specific ternary operator. Depending on the debugger this will cause it to display either the default value of the class name, or an error indicating which part of the syntax could not be evaluated; this may be important if you work in a multi-language environment, or if you ship your classes as a library to customers.

关于c# - DebuggerDisplayAttribute - 它如何在评估表达式时选择语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1458176/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com