我有一個PostSharp方面(以下實現爲AutoData
)施加於測試方法,例如:如何確定編織方法?
[Theory, AutoData(additionalTypes: typeof(MethodFormatter))] public void MethodFormatsAsExpected(FormatterFactory sut) { var name = MethodBase .GetCurrentMethod() .Name; // Resolves to "<MethodFormatsAsExpected>z__OriginalMethod" }
正如可以看到的,MethodBase.GetCurrentMethod
結果被返回編織體。我想,而不是檢索方面已經編織了(父)目標方法,基本上是等效的:
var method = GetType() .GetMethod(nameof(MethodFormatsAsExpected)) .Name; // Returns "MethodFormatsAsExpected"
但像什麼MethodBase.GetCurrentMethod
提供了一個通用的,靜態的方式。
這可能嗎?
WOW ...抱歉,對此作出延遲迴應。我從來沒有收到通知。非常好的工作。 :) –