I find that the best way to work out how to build expression trees is to see what the C# compiler does. So here's a complete program: using System; using System.Linq. Expressions; public class Foo { public int X { get; set; } public int Y { get; set; } } class Test { static void Main() { Expression> builder = z => new Foo { X = z, Y = z }; } } Compile that, open the results in Reflector and set the optimisation to .
NET 2.0. You end up with this generated code for the Main method: ParameterExpression expression2; Expression> expression = Expression. Lambda>( Expression.
MemberInit( Expression. New((ConstructorInfo) methodof(Foo..ctor), new Expression0), new MemberBinding { Expression. Bind((MethodInfo) methodof(Foo.
Set_X), expression2 = Expression. Parameter(typeof(int), "z")), Expression. Bind((MethodInfo) methodof(Foo.
Set_Y), expression2) } ), new ParameterExpression { expression2 }) Basically, I think Expression. MemberInit is what you're after.
I find that the best way to work out how to build expression trees is to see what the C# compiler does. So here's a complete program: using System; using System.Linq. Expressions; public class Foo { public int X { get; set; } public int Y { get; set; } } class Test { static void Main() { Expression> builder = z => new Foo { X = z, Y = z }; } } Compile that, open the results in Reflector and set the optimisation to .
NET 2.0. You end up with this generated code for the Main method: ParameterExpression expression2; Expression> expression = Expression. Lambda>( Expression.
MemberInit( Expression. New((ConstructorInfo) methodof(Foo..ctor), new Expression0), new MemberBinding { Expression. Bind((MethodInfo) methodof(Foo.
Set_X), expression2 = Expression. Parameter(typeof(int), "z")), Expression. Bind((MethodInfo) methodof(Foo.
Set_Y), expression2) } ), new ParameterExpression { expression2 }); Basically, I think Expression. MemberInit is what you're after.
Jon great idea. I would give you 100 up votes for that solution! :-) – gsharp Apr 27 '10 at 8:46 Jon, brilliant!
Many thanks indeed! I agree with gsharp, a great idea! - Reflector is my new friend :-) Thanks again – jameschinnock Apr 27 '10 at 9:22 @GSharp, I'll help you with that: +1.
– Steven Apr 27 '10 at 10:21.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.