如何为 html 助手制作这个表达式?
How make this expression for html helpers?
我有两个类
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
并且它必须取决于当前的文化
怎么做到的?
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);
}
我有两个类
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
并且它必须取决于当前的文化
怎么做到的?
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);
}