我有两个班级
public class LocalizedString {
public string Ru { get; set; }
public string Kk { get; set; }
public string En { get; set; }
}
public class Person {
public LocalizedString FirstName { get; set; }
public LocalizedString LastName { get; set; }
}
我需要像x => x.FirstName.Ru
这样的表达式
@Html.TextBoxFor(x => x.FirstName.Ru)
和LastName
,它必须取决于当前的文化
怎么做?
答案 0 :(得分:0)
public static Expression<Func<T, string>> GetMember<T>(
Expression<Func<T, LocalizedString>> expression) {
MemberExpression member = expression.Body as MemberExpression;
PropertyInfo propInfo = member.Member as PropertyInfo;
var param = Expression.Parameter(typeof(T), "x");
Expression propertyLambda = Expression.Property(param, propInfo.Name);
propertyLambda = Expression.Property(propertyLambda, "Ru");
return Expression.Lambda<Func<T, string>>(propertyLambda, param);
}