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에서, 당신은 할 수 너무 깊어지면 나갈 수 있습니다.
이전에는 호출 된 각 함수의 성능을보기 위해 호출 스택 뷰어를 빌드했습니다. 이것은 여분의 코드로 인해 함수/서브마다 하나의 VBS 코드 라인이 필요하고 런타임 동안 약간의 오버 헤드가 필요합니다.
하단 - 최대 :
함수가 호출 될 때마다Function DoSomething(a, b, c)
dim registerFunctionObj : Set registerFunctionObj = [new RegisterFunction]("DoSomething")
' other code
End Function
이는 RegisterFunction 개체의 새 인스턴스를 만듭니다. 함수가 종료되면 registerFunctionObj
변수가 자동으로 범위를 벗어나서 인스턴스의 Class_Terminate 하위를 호출합니다.
[new 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
면책 조항 : 여기의 코드는 즉석에서 만든 순수 데모 코드입니다. 기능이 부족하고 개념을 설명하기 위해 여기에만 있습니다. 오류가있을 수 있으며 완료되지 않았습니다.
필요한 것은 함수 당 한 줄의 코드와 그것을 확장하는 자신의 상상력뿐입니다.
이 재미있는, 나는 그것을 체크 아웃해야 할거야 ... – coson
내가 찾던 내용이 아닙니다. 나는 프로그래밍 방식으로 무언가를 찾고있다. – coson
나도 알아, 당신이 linenumber you'r에 대한 오랜 자신을 찾고 있었지만, 또한 가능하지 않다, 지금은 내가 그렇게 사치를 가지고 루비에서 스크립팅이야 – peter