[英]I can't access property on my object via Expression.Property unless the type of the fed expression is strongly-typed
[英]How can I Create a Expression.Property of a child object
通常我會以這種方式創建一個表達式。
ParameterExpression pe = Expression.Parameter(typeof(object1), "x");
string Name = "property1";
MemberExpression left = Expression.Property(pe, (object1).GetProperty(Name));
它產生left = x => x.property1
我需要知道我該如何制作
left = x => x.Object2.property1
如果Name =“Object2.property1”; 和object2是object1的子項
提前致謝
我不太明白你想要什么。 它是一個屬性鏈(例如: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.