我有这样一个静态列表:
class Program
{
public static List<Action> List { get; set; } = new List<Action>();
static void Main(string[] args)
{
Test test = new Test();
test.Work();
var type = test.GetType();
var method = type.GetMethod("Action1",System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.NonPublic);
//Console.WriteLine(List.Any(p => p == new Action(method.)));
}
}
public class Test
{
public void Work()
{
Program.List.Add(new Action(Action1));
}
private void Action1()
{
}
}如何通过反射判断Program.List包含的Action1?
如果Action1方法是公共的,我可以这样做:
Console.WriteLine(List.Any(p => p == new Action(test.Action1)));它将印刷“真”;
发布于 2016-11-09 07:39:18
试试这个:
Console.WriteLine(List.Any(p => p.Method.MethodHandle.Value == method.MethodHandle.Value));https://stackoverflow.com/questions/40501736
复制相似问题