是否可以在 VB.NET 中的 DebuggerDisplay 中使用条件?

Is it possible to use conditions in a DebuggerDisplay in VB.NET?

我把问过的问题here再问一遍因为答案不适合VB.NET:

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?

如何在 VB.NET 中执行此操作?

VB 现在有自己的 C# ?: 运算符,即 If。可以用在等价场景:

<DebuggerDisplay("{GetType(FileWrapper).Name,nq}: FileName = {FileName,nq}{If(IsTempFile, "", TempFileName: "" & TempFileName, System.String.Empty),nq}")>
Public Class FileWrapper

    Public Property FileName As String
    Public Property IsTempFile As Boolean
    Public Property TempFileName As String

End Class

似乎 GetType 在那里被解释为 VB 运算符而不是 Object.GetType 方法,因此您也需要在其中添加类型作为参数。

同样值得查看原始线程中的第二个答案。我从表面上接受它包含的关于调用代码的编译器是评估所提供表达式的编译器的声明。这意味着如果该类型被用其他语言编写的代码使用,则该上下文中特定于 C# 或 VB 的表达式将失败。