次のデリゲートがあるとしましょう。
public delegate void Example();
および次のようなクラス:
public class TestClass {
Example FailingTest = () => Assert.Equal(0,1);
}
リフレクションを使用して「FailingTest」という名前を取得するにはどうすればよいですか?
これまでのところ、私は試しました:
var possibleFields = typeof(TestClass).GetFields(relevant_binding_flags)
.Where(x => x.FieldType.Equals(typeof(Example)));
foreach(FieldInfo oneField in possibleFields) {
// HERE I am able to access the declaring type name
var className = oneField.ReflectedType.Name; // == "TestClass"
// but I am not able to access the field
// name "FailingTest" because:
var fieldName = oneField.Name; // == "CS$<>9__CachedAnonymousMethodDelegate1"
}
デバッガーでステップスルーすると、宣言されたフィールド「FailingTest」の名前へのパスが見つかりません。
その情報は実行時に保持されますか、それとも匿名デリゲートが割り当てられると失われますか?