VBScriptで現在実行中の関数の名前を調べることは可能ですか?ノーVBScript実行中の関数を確認する
MethodBase method = MethodBase.GetCurrentMethod();
Console.WriteLine(method.Name);
VBScriptで現在実行中の関数の名前を調べることは可能ですか?ノーVBScript実行中の関数を確認する
MethodBase method = MethodBase.GetCurrentMethod();
Console.WriteLine(method.Name);
をしますが、簡単にそれが再帰の場合
dim module_name
sub sub1
module_name = "sub1"
wscript.echo "i'm " & module_name
'do something
end sub
function function1
module_name = "function1"
wscript.echo "i'm " & module_name
function1 = "something"
end function
あなたにもなるようにレベルyou'rを覚えることができる実装できます。
.NETでは、あなたが行うことができますあなたはあまりにも深くなったら外出することができます。
以前は、呼び出された各関数のパフォーマンスを見るためにコールスタックビューアを作成しました。これには、機能/サブごとに1行のVBSコードが必要であり、余分なコードのためにランタイム中にいくつかのオーバーヘッドが必要です。
ボトム - アップ:関数が呼び出されるたび
Function DoSomething(a, b, c)
dim registerFunctionObj : Set registerFunctionObj = [new RegisterFunction]("DoSomething")
' other code
End Function
、それはRegisterFunctionオブジェクトの新しいインスタンスを作成します。関数が終了すると、registerFunctionObj
変数がスコープから自動的に外れ、インスタンスのClass_Terminateサブフォームが呼び出されます。
[new RegisterFunction]
はregisterFunctionインスタンスを返すだけの関数である。
Function [new RegisterFunction](funcName)
Set [new RegisterFunction] = new cls_RegisterFunction
[new RegisterFunction].FunctionName = funcName
Set [new RegisterFunction].CallStackViewer = CallStackViewer
End function
Class cls_RegisterFunction
Private functionName_, startTime_, callStackViewer_, endTime_
Private Sub Class_Initialize
startTime_ = now
callStackViewer_.LogInitialize me
End Sub
Public Property Let FunctionName(fName)
functionName_ = fName
End Property
Public Property Set CallStackViewer(byRef csv)
Set callStackViewer_ = csv
End Property
Private Sub Class_Terminate
endTime_ = now
callStackViewer_.LogTerminate me
End Sub
End Class
CallStackViewerインスタンスがCallStackViewerクラスのシングルトンインスタンスですが、あなたはそれを取得するので、あなたは、そのプロジェクトの一部にすることができますあなたを通してグローバルプロジェクトクラス:
Private PRIV_callStackViewer
Public Function CallStackViewer()
If not IsObject(PRIV_callStackViewer) Then
Set PRIV_callStackViewer = new cls_CallStackViewer
End If
Set CallStackViewer = PRIV_callStackViewer
End Function
Class cls_CallStackViewer
Public Sub Class_Initialize
' Here you can retrieve all function libraries (as text file) extract the
' function name, the file they are in and the linenumber
' Put them in a dictionary or a custom object
End Sub
Public Sub LogInitialize(byref registerFunction)
' Here you can push the function on a stack (use a standard dotnet list>stack for it),
' log the starttime to a log object or handle custom breakpoints
End Sub
Public Sub LogTerminate(byref registerFunction)
' Here you can pop the function from a stack, log the endtime to a log
' object or handle custom breakpoints
End Sub
End Class
免責事項:コードここでは、その場で作成された純粋なデモコードです。それは機能性がなく、概念を説明するためだけに存在します。エラーを含む可能性があり、完全ではありません。
必要なのは、機能ごとに1行のコードとそれを拡張する独自の想像力だけです。
これは面白いです。 ... – coson
私が探していたものではありません。私はプログラム的に何かを探しています。 – coson
私が知っているのは、長い間あなたの上にある行番号のために見てきましたが、また不可能です。今はRubyでスクリプトを作成していますので、私はこのような贅沢を持っています – peter