这里是我的方法:ExpressionTree - GetSetMethod错误:方法 'System.String GET_NAME()' 没有为类型 'System.String' 定义
public static MethodCallExpression ClonePropertyAssignmentLambda<T>(Expression source, string property)
{
var targetExp = Expression.Parameter(typeof (T), "target");
var propertyInfo = typeof (T).GetProperty(property);
var targetProperty = Expression.Property(targetExp, propertyInfo);
var sourceProperty = Expression.Property(source, propertyInfo);
return Expression.Call(targetProperty, ((PropertyInfo) targetProperty.Member).GetSetMethod(), sourceProperty);
}
这里是我怎样,我称之为:
ClonePropertyAssignmentLambda<Person>(source, "Name")
我得到了Expression.Call行上的错误。如果我调用GetGetMethod,则会出现类似的错误。
谢谢,你明白了。 – chief7 2010-10-08 15:33:10