我想将Concat的两个表达式用于最终表达式
Expression<Func<T,string>>
所以我创建了表达式belwo代码只适用于字符串类型,如果我将memberExpression作为Int32或DateTime抛出异常
类型’system.int32’的表达式不能用于方法’System.String Concat(System.String,System.String)’的’System.String’类型的参数
如果我将表达式转换为
var conversion = Expression.Convert(memberExpression,typeof (string));
获取没有强制运算符是在类型’system.int32’和’System.String’之间定义的.
请帮我解决
码
MethodInfo bodyContactMethod = typeof (string).getmethod("Concat",new[] {typeof (string),typeof (string)}); ParameterExpression parameter = Expression.Parameter(typeof (T)); body = Expression.Call(bodyContactMethod,cons,memberExpression); return Expression.Lambda<Func<T,string>>(body,parameter);