private static MethodInfo createAssignerMethod = typeof(Program).GetMethod("CreateAssignerImpl", BindingFlags.NonPublic | BindingFlags.Static);
public static void Main()
var assigners = typeof(Foo).GetProperties().Select(x => CreateAssigner<Foo>(x)).ToList();
var from = new Foo() { A = 3, B = "test" };
foreach (var assigner in assigners)
private static Action<T, T> CreateAssigner<T>(PropertyInfo propertyInfo)
return (Action<T, T>)createAssignerMethod.MakeGenericMethod(typeof(T), propertyInfo.PropertyType).Invoke(null, new object[] { propertyInfo });
private static Action<T, T> CreateAssignerImpl<T, TProperty>(PropertyInfo propertyInfo)
var getMethod = propertyInfo.GetGetMethod();
var getDelegate = (Func<T, TProperty>)Delegate.CreateDelegate(typeof(Func<T, TProperty>), null, getMethod);
var setMethod = propertyInfo.GetSetMethod();
var setDelegate = (Action<T, TProperty>)Delegate.CreateDelegate(typeof(Action<T, TProperty>), null, setMethod);
return (x, y) => setDelegate(y, getDelegate(x));
public int A { get; set; }
public string B { get; set; }