[英]Cast from generic class property
我想从propertyType的通用类进行转换,并且不知道该怎么做。
我想做这样的事情:
var key = Expression.Property(genericType, rule.ComparisonPredicate);
Type propertyType = typeof(T).GetProperty(rule.ComparisonPredicate).PropertyType;
var converter = TypeDescriptor.GetConverter(propertyType);
var value = Expression.Constant((propertyType)converter.ConvertFromString(rule.ComparisonValue) );
但是在行var值中我遇到了一个错误:
'propertyType'是一个变量,但是像类型一样使用
您不能转换为变量,应指定实型
var value = Expression.Constant(( propertyType )converter.ConvertFromString(rule.ComparisonValue));
尝试转换属性类型
(类型)typeof(T).GetProperty(rule.ComparisonPredicate).PropertyType
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.