How to instantiate an Expression.Property child object

I usually create an expression this way.

ParameterExpression pe = Expression.Parameter(typeof(object1), "x"); string Name = "property1"; MemberExpression left = Expression.Property(pe, (object1).GetProperty(Name)); 

it produces left = x => x.property1

I need to know how I can create

left = x => x.Object2.property1

if Name = "Object2.property1"; and object2 is a child of object1

Thank you in advance

+4
source share
1 answer

I do not quite understand what you want. Is this a property chain (say: x.Prop1.Prop2)?

 var pe = Expression.Parameter(typeof(object1)); var property1 = typeof(object1).GetProperty(Name1); var property2 = property1.PropertyType.GetProperty(Name2); var inner = Expression.Property(pe, property1); var outer = Expression.Property(inner, property2); 
+21
source

All Articles