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

呼び出し元の引数の変数名を取得できた。他言語のEval()があれば、またはVB14以降なら変数の値も表示できそうだが・・・
1
2
3
4
add(1,3)
x
y
4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
 
 
 
    ''' <summary>
    ''' 入力チェック
    ''' </summary>
    ''' <param name="args">変数を与える(可変長)
    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

コメント

このブログの人気の投稿

Python OpenCVとWebカメラでバーコードリーダー

VB.net Dictionaryクラスの初期化