フォーラムのどこかにすでに答えがあると思いますが、今のところそれを見つけることができていません。この例のように、異なるパラメーターを持つ異なるメソッドを持つために、デリゲートと組み合わせて匿名メソッドを使用していますが、同じリターンタイプはすべて関数パラメーターとして機能します。
public delegate TestCaseResult Action();
...
[TestDescription("Test whether the target computer has teaming configured")]
public TestCaseResult TargetHasOneTeam()
{
// do some logic here and return
// TestCaseResult
}
[TestDescription("Test whether the target computer has the named team configured")]
public TestCaseResult TargetHasNamedTeam(string teamName)
{
// do some logic here and return
// TestCaseResult
}
...
public static void TestThat(TestCaseBase.Action action)
{
TestCaseResult result = action.Invoke();
// I want to get the value of the TestDescription attribute here
}
...
// usage
TestThat(() => TargetHasOneTeam());
TestThat(() => TargetHasNamedTeam("Adapter5"));
例からわかるように、TestThat()関数内からTestDescriptionAttribute属性を取得できるようにしたいと思います。メソッドを含むActionパラメーターを既に確認しましたが、TargetHasOneTeam()メソッドを「見つける」ことができませんでした。