public class Model1 { public String Value { get; set; } } public class Model2 { public dynamic Value { get; set; } } public static Expression<Func<Model2,Model1>> GetExpression() { return f => new Model1 { Value = f.Value }; }
我正在编写一个GetExpression(),它将Model2属性转换为Model1.说到动态属性,我尝试Convert.ToString(f.Value)或(String)f.Value但它说
“An expression tree may not contain a dynamic operation”
任何人都知道在表达式中将动态值转换为类型值的正确方法是什么?