Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Swap<T>(Expression<Func<T>> left, Expression<Func<T>> right)
- {
- var lvalue = left.Compile()();
- Expression.Lambda<Func<T>>(Expression.Assign(left.Body, Expression.Constant(right.Compile()()))).Compile()();
- Expression.Lambda<Func<T>>(Expression.Assign(right.Body, Expression.Constant(lvalue))).Compile()();
- }
- public class Test
- {
- public int X { get; set; }
- public int Y { get; set; }
- }
- static void Main()
- {
- var obj = new Test() { X = 123, Y = 456, };
- Swap(() => obj.X, () => obj.Y);
- Console.WriteLine("obj.X = {0}, obj.Y = {1}", obj.X, obj.Y);
- }
Add Comment
Please, Sign In to add comment