public static Action <object, object> CreatePropertyCloner(PropertyInfo property) { if (property.ReflectedType.IsValueType) { return(new Action <object, object>((source, target) => { var value = CreatePropertyGetter(property)(source); CreatePropertySetter(property)(target, value); })); } else { var expSource = Expression.Parameter(typeof(object), "source"); var expTarget = Expression.Parameter(typeof(object), "target"); var expPropertySource = Expression.Property(Expression.Convert(expSource, property.ReflectedType), property); var main = Expression.Call(Expression.Convert(expTarget, property.ReflectedType), property.GetSetMethod(true), expPropertySource); return((Action <object, object>)Expression.Lambda(typeof(Action <object, object>), main, expSource, expTarget).Compile()); } }
public static Action <object, object> CreatePropertyCloner(PropertyInfo property) { ParameterExpression expression; ParameterExpression expression2; Action <object, object> action2 = null; if (property.ReflectedType.IsValueType) { if (action2 == null) { action2 = delegate(object source, object target) { object obj2 = CreatePropertyGetter(property)(source); CreatePropertySetter(property)(target, obj2); }; } return(action2); } MemberExpression expression3 = Expression.Property(Expression.Convert(expression = Expression.Parameter(typeof(object), "source"), property.ReflectedType), property); MethodCallExpression body = Expression.Call(Expression.Convert(expression2 = Expression.Parameter(typeof(object), "target"), property.ReflectedType), property.GetSetMethod(true), new Expression[] { expression3 }); return((Action <object, object>)Expression.Lambda(typeof(Action <object, object>), body, new ParameterExpression[] { expression, expression2 }).Compile()); }