日期:2014-05-20  浏览次数:20975 次

Expression.Call的问题
本帖最后由 z1101385391 于 2013-07-16 12:06:17 编辑

public IEnumerator<TEntity> GetEnumerator()
        {
            return Execute<IEnumerator<TEntity>>(Expression.Call(Expression,
(MethodInfo)MethodBase.GetCurrentMethod()));
        }


像上面这么写会报这个错误
方法 System.Collections.Generic.IEnumerator`1[TEntity] GetEnumerator() 包含泛型参数
改成这样

public IEnumerator<TEntity> GetEnumerator()
        {
            return Execute<IEnumerator<TEntity>>(Expression.Call(Expression, 
((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(typeof(TEntity))));
        }


会报这个错误
System.Collections.Generic.IEnumerator`1[TEntity] GetEnumerator() 不是 GenericMethodDefinition。只能对 MethodBase.IsGenericMethodDefinition 为 True 的方法调用 MakeGenericMethod。

要怎么写才是正确的?

------解决方案--------------------
Execute方法在哪里定义的。