【发布时间】:2014-10-23 15:11:22
【问题描述】:
我正在使用反射来调用泛型方法:
public DataTable GetEntityData<T>(string EntitiesType, string Query, int Page, List<string> Columns, string OrderByClause, object[] QueryArgs)
{
using (var model = new MK3Entities())
{
Type ET = GetEntitiesType(EntitiesType);
MethodInfo method = typeof(MK3Entities).GetMethod("GetEntityData");
MethodInfo generic = method.MakeGenericMethod(ET);
var obj = (generic.Invoke(model, new object[] { Query, NUMBEROFWIDGETRESULTS, Page, Columns, OrderByClause, QueryArgs }) as DataTable);
return obj;
}
}
我在这里通过反射调用的方法接受一个通用委托,该委托执行后处理。
GetEntityData(reflection invoked) 函数将委托作为参数方法存根和委托声明:
public delegate IEnumerable<T> PostProcessing<T>(IEnumerable<T> Source) where T : class;
public DataTable GetEntityData<D>(string Query, int NumbOfResults, int Skip, List<string> Columns, string OrderByClause, object[] QueryArgs, PostProcessing<D> PostDelegate)
where D : class
{
}
在创建泛型方法的第一个 GetEntityData<T> 内部,我还需要创建一个泛型方法作为委托作为参数传入,该参数将变量 ET 作为类型传递。
有人知道我该怎么做吗?
【问题讨论】:
标签: c# generics reflection parameters delegates