重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

反射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动态快速赋值
地址分享:http://cqcxhl.com/article/gsdode.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP