0

一般的な手法を使用して、ネイティブ型を模倣した構造を作成しようとしています。これは制約付きの数値です (制約はサンプルには示されていません)。

<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

満足できず、変更したいデフォルトの印刷出力を除いて、すべて問題ありません。出来ますか?

変数を宣言すると:

Dim ID As New DbKey(12)

次に、即時ペインで:

ケース 1:

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

結果:

Application1.DbKeyModule+DbKey

ケース 2:

? ID

結果:

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

これら 2 つのデフォルト出力の一方または両方を別のものに変更できますか?

注: 必要なメソッド、演算子、および型キャストを宣言したため、式は"Value is " & ID正しくID.ToString()動作します。しかし、上記の 2 つの式は、これらの手段では制御できないオブジェクトから文字列への形式を参照しています。変更できますか?

4

1 に答える 1