C# 无法使用GetMethod找到私有void泛型函数
我有一个具有以下签名的函数:C# 无法使用GetMethod找到私有void泛型函数,c#,reflection,C#,Reflection,我有一个具有以下签名的函数: private void Foo<TPoco>(IContext context, List<TPoco> pocos, DateTime modifiedDateTime) where TPoco : MyAbstractClass 这在类中找到了14个其他方法,但不是这个。它确实发现了这种方法: protected void Bar<TContext, TPoco>(List<TPoco> pocosTo
private void Foo<TPoco>(IContext context, List<TPoco> pocos, DateTime modifiedDateTime)
where TPoco : MyAbstractClass
这在类中找到了14个其他方法,但不是这个。它确实发现了这种方法:
protected void Bar<TContext, TPoco>(List<TPoco> pocosToPersist, TContext context)
where TContext : IContext, new()
where TPoco : MyAbstractClass
我仍然看不到这个函数。正如帖子上的评论所指出的,代码应该是有效的。问题是我在其中定义函数的类是抽象的,所以我无法找到私有函数
如果我执行
this.GetType().BaseType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
,函数将按预期显示。您上次的尝试应该可以正常工作。您在调用哪个对象GetType
?问题一定出在其他地方。将函数和反射调用复制到一个新项目或类似.Net FIDLE的东西中,您将看到您在这里发布的代码工作得完美无缺。是的,你们都是对的-私有函数在一个抽象类中,因此GetType()得到的类型与我预期的不同。
protected void Bar<TContext, TPoco>(List<TPoco> pocosToPersist, TContext context)
where TContext : IContext, new()
where TPoco : MyAbstractClass
GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance )