这是我的代码
var propertIEs = type.GetPropertIEs();foreach (var propertyInfo in propertIEs){ model.ModelPropertIEs.Add( new keyvaluePair<Type,string> (propertyInfo.PropertyType.name,propertyInfo.name) );}
这个代码propertyInfo.PropertyType.name是好的,但如果我的属性类型是Nullable我得到这个Nullable’1字符串,如果写Fullname如果得到这个搅拌System.Nullable1 [[System.DateTime,mscorlib,版本= 4.0.0.0,Culture =中立,PublicKeyToken = b77a5c561934e089]]
解决方法 更改代码以查找可空类型,在这种情况下,将PropertyType作为第一个通用的agruement:var propertyType = propertyInfo.PropertyType;if (propertyType.IsGenericType && propertyType.GetGenericTypeDeFinition() == typeof(Nullable<>)) { propertyType = propertyType.GetGenericArguments()[0]; }model.ModelPropertIEs.Add(new keyvaluePair<Type,string> (propertyType.name,propertyInfo.name));总结
以上是内存溢出为你收集整理的c# – 从Nullable类型的反射中获取PropertyType.Name全部内容,希望文章能够帮你解决c# – 从Nullable类型的反射中获取PropertyType.Name所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)