开发者

TypeArgumentException in silverlight lambda expression

I've defined the following method

public static Expression<Func<T,dynamic>> CreateExpression(string propName)
{
ParameterExpression param = Expression.Parameter(typeof(T));

MemberExpression aggregator = Expression.PropertyOrField(parameter,propName);

return Expression.Lambda<Func<T,dynamic>>(aggregator,param);
}

The code compiles OK but in the runtime the last line throws argumentexception stating 'Expression of Type开发者_Python百科 'System.Int32' cannot be used for return type 'System.Object'

Am i missing something?

Thanks in advance


Use Expression.Convert. That will add the boxing conversion you require to turn the Int32 basic type (or any basic type you reference) into an object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜