vb.net 呼び出し元の引数の変数名を表示する

呼び出し元の引数の変数名を取得できた。他言語のEval()があれば、またはVB14以降なら変数の値も表示できそうだが・・・
add(1,3)
x
y
4
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Debug.Print(add(1, 3))
    End Sub


    Function add(x As Integer, y As Integer) As Integer

        FuncPrint(x, y)

        Return x + y
    End Function



    ''' 
    ''' 入力チェック
    ''' 
    ''' 変数を与える(可変長)
    Public Sub FuncPrint(ParamArray args As Object())

        Dim s As String = ""


        If (args Is Nothing) Or (args.Length = 0) Then
            '引数なし
        Else
            s = String.Join(",", args)
        End If

        s = New StackFrame(1).GetMethod.Name + "(" + s + ")"
        Debug.Print(s)


        For Each item In New StackFrame(1).GetMethod.GetParameters
            Debug.Print(item.Name)
        Next


    End Sub

End Class

コメント

このブログの人気の投稿

VB.net Dictionaryクラスの初期化

VB.NET 実行中のクラス名とメソッド名を取得

フルパスファイル名と日付をサブディレクトリ込みで取得する方法