反射model动态快速赋值-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

反射model动态快速赋值

XMLopr xmlpro = new XMLopr();
string xmlpath = WebConfigurationManager.AppSettings["fileinfo_Filexmlpath"].ToString();
xmlpath = Server.MapPath(xmlpath);
Dictionary filedmap = xmlpro.ReadXmlFiled(xmlpath);
if (filedmap == null)
{
result="读取字段匹配设置文档失败!";
return result;
}
int i = 0;
foreach (KeyValuePair keypair in filedmap)
{
//获取值
string value =dr[keypair.Key.Trim()]==null?"":dr[keypair.Key.Trim()].ToString().Trim();
//获取映射字段
string mapfiled = keypair.Value.Trim();
//判断映射字段类型
PropertyInfo property = fileModel.GetType().GetProperty(mapfiled);
if (property.PropertyType.Name.ToLower().Equals("string"))
{
property.SetValue(fileModel,value,null);
}
else if (property.PropertyType.Name.Equals("int32"))
{
property.SetValue(fileModel, int.Parse(value), null);
}
else if (property.PropertyType.Name.Equals("DateTime"))
{
if(value.Trim()!=string.Empty)
property.SetValue(fileModel,DateTime.Parse(value), null);
}
}

 

创新互联公司主营云州网站建设的网络公司,主营网站建设方案,app开发定制,云州h5微信小程序定制开发搭建,云州网站营销推广欢迎云州等地区企业咨询


标题名称:反射model动态快速赋值
URL网址:http://kswsj.cn/article/gsdode.html

其他资讯