這裏是我的方法: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