首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

利用反射将数据读入实体类时的类型转换解决方法

2012-03-05 
利用反射将数据读入实体类时的类型转换PropertyInfo[]propertiesxxxx.GetType().GetProperties()for(int

利用反射将数据读入实体类时的类型转换
PropertyInfo[]   properties   =   xxxx.GetType().GetProperties();

for(int   i   ;i <properties.Length;i++)
                                        {
                                                                                        propertids[i].SetValue(xxxx,aString[i],   null);
                                        }

现在的问题是如何根据这个property的类型(如string,bool,int),把aString[i]的类型进行相应的转换.


比如 xxx,有个属性是
public   int   a
{
set...

}
那么我希望把aString转换成int

public   bool   b
{
set...

}
那么我希望把aString转换成bool  

比较笨的方法就是用case或if,不知道有没有其他方法


[解决办法]
使用Convert.ChangeType

热点排行