简体   繁体   English

如何创建子对象的Expression.Property

[英]How can I Create a Expression.Property of a child object

normally I create an expresion in 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 它产生left = x => x.property1

I need to know how can I produce 我需要知道我该如何制作

left = x => x.Object2.property1

if Name = "Object2.property1"; 如果Name =“Object2.property1”; and object2 is a child to object1 和object2是object1的子项

Thanks in advance 提前致谢

I don't quite understand what you want. 我不太明白你想要什么。 Is it a property chain (say: x.Prop1.Prop2)? 它是一个属性链(例如: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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM