简体   繁体   English

可以更改表示结构打印输出的默认字符串吗?

[英]Can default strings representing structure printout be changed?

I'm trying to use common technique to create structure mimicking native type, it is constrained number (constraint not shown in sample): 我正在尝试使用通用技术来创建模仿本机类型的结构,它是受约束的数字(约束未在示例中显示):

<HideModuleName> _
Public Module DbKeyModule

    <DebuggerDisplay("ID = {Value}")> _
    Structure DbKey
        Implements IComparable(Of DbKey)
        Implements IEquatable(Of DbKey)

        Const Null As Integer = 0

        ReadOnly Property Value() As Integer
            Get
                Return _Value
            End Get
        End Property

        Overloads Function ToString() As String
            Return If(_Value <> 0, _Value.ToString(InvariantCulture.NumberFormat), "NULL")
        End Function
        'GetHashCode(), Equals(), CompareTo() follow
        'constructors follow
        'operator definitions follow
        'type conversions definitions follow
    End Structure
End Module

All is fine except some default printouts I'm not satisified with and want to change them. 一切都很好,除了一些我不满意的默认打印输出,我想更改它们。 Is it possible? 可能吗?

If I declare a variable: 如果我声明一个变量:

Dim ID As New DbKey(12)

Then in immediate pane: 然后在即时窗格中:

Case 1: 情况1:

? String.Format("{0}", ID))

Result: 结果:

Application1.DbKeyModule+DbKey

Case 2: 情况2:

? ID

Result: 结果:

ID = 12
    _Value: 12
    Null: 0
    Value: 12

Can be one or both these two default outputs changed to something else? 可以将这两个默认输出之一或全部更改为其他内容吗?

Note: Expressions like "Value is " & ID or ID.ToString() work correctly because I declared necessary methods, operators and typecasts. 注意:因为我声明了必要的方法,运算符和类型转换,所以"Value is " & IDID.ToString()类的表达式可以正常工作。 But the above two expressions are referring to some object-to-string form beyond the control of these means. 但是以上两个表达式是指超出这些方法控制范围的某些对象到字符串的形式。 Can it be changed? 可以更改吗?

After all I guess the printouts are specific product of 毕竟我猜打印的是

  • String.Format() method in Case 1 案例1中的String.Format()方法
  • Debug.Print() method in Case 2 案例2中的Debug.Print()方法

and therefore they cannot be changed. 因此,它们无法更改。

Didn't take time to verify in reference source though. 没花时间在参考源中进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM