我看过其他问题,如this,但我没有运气。我觉得我在回答中跳舞。调用调用导致参数计数不匹配
myMethod --> Int32 Count[MyClass](System.Data.IDbConnection, ICriteria)
...我尝试调用它像这样使用调用:
使用反射来调用MethodInfo myMethod = MakeGenericMethod(Type.GetType(MyClass))
我有一个MethodInfo
对象,看起来像这样在调试后
ICriteria myCriteria = new Criteria("some info here");
//'connection' is an object of type System.Data.IDBConnection
int count = (int)myMethod.Invoke(connection, new object [] {myCriteria});
...但是当我这样做时,我得到一个参数计数不匹配,我为什么挠挠我的头。
这是因为它是一种通用的方法,可能吗?或者,Count
是connection
的扩展方法?
仅供参考,叫我的方法是像int count = connection.Count<MyRow>(new Criteria("some info here"));
非常感谢你,你的建议效果很好。扩展方法位在我的眼睛上玩弄技巧。 – jkj2000