在我的代码使用反射像这样得到一个属性的类型:如何将属性从一种类型转换为另一种?
foreach(FilterRule rule in filter.Rules)
{
PropertyInfo property = typeof(T).GetProperty(rule.Field);
}
之后我做几项检查,找出哪些类型实际上,如果类型是long?
:
else if (property.PropertyType == typeof(long?))
{
long dd = Convert.ChangeType(rule.Field, System.Int64);
}
我想转换为System.Int64
类型。或者更具体到只是long
没有可为空,但似乎我没有得到这个,因为rule.Field
是String
它说第一个参数应该是object
,我看到有一些霸主,但没有使用的语法,我正在尝试。
我该如何做这种转换?