B
bittercoder
I have an Lambda expression which is effectively a
MemberInitExpression... recursively creating a tree of types i.e.
Init(Expression<Func<Dog>> expr) { ...}
Init( () => new Dog()
{
Name = "Bill",
Fleas =
{
new Flea() { Name = "Murray"},
new Flea() { Name = "John" }
}
});
What I'd like to do is actually replace the MemberInitExpression (and
the corresponding NewExpression) with a call to an external static
factory method... (say using MethodCallExpression) yet still retain
all the member bindings... and be able to walk the expression tree
doing it for all MemberInit expressions (so new Dog() would become
Factory.Create<Dog>, new Flea() would become Factory.Create<Flea>
etc.)
Anyone have any suggestions on how to do that easily - I've had a
quick experiment, but couldn't see any easy way to retain all the
existing MemberBindings.
Chez,
- Alex
MemberInitExpression... recursively creating a tree of types i.e.
Init(Expression<Func<Dog>> expr) { ...}
Init( () => new Dog()
{
Name = "Bill",
Fleas =
{
new Flea() { Name = "Murray"},
new Flea() { Name = "John" }
}
});
What I'd like to do is actually replace the MemberInitExpression (and
the corresponding NewExpression) with a call to an external static
factory method... (say using MethodCallExpression) yet still retain
all the member bindings... and be able to walk the expression tree
doing it for all MemberInit expressions (so new Dog() would become
Factory.Create<Dog>, new Flea() would become Factory.Create<Flea>
etc.)
Anyone have any suggestions on how to do that easily - I've had a
quick experiment, but couldn't see any easy way to retain all the
existing MemberBindings.
Chez,
- Alex