I need to generate expression tree than checks two objects (arguments) for equality. I know that these objects will have properties, so I have to compare their values, how to do this?
So i have something like obj1
, obj2
and array of strings with property names i need to check.
Here's how i see this :
var leftObject = E.Parameter(typeof (object), "leftObject");
var rightObject = E.Parameter(typeof (object), "rightObject");
var properties = E.Parameter(typeof (string[]), "properties");
var i = E.Parameter(typeof(int), "i");
var equal = E.Parameter(typeof (bool), "equal");
var body = E.Block
(
new[] { properties, i},
E.Assign(properties,E.Constant(props)),
E.Assign(i,E.Constant(0)),
E.Assign(equal,E.Constant(true)),
E.Loop
(
E.Property(leftObject,props[i]) == E.Property(rightObject,props[i])
)
);
How to implement accessing to properties one by one in Loop?
P.S. E
is my alias for Expression
.