////// 把Model转换为DataRow /// ////// /// public static T ParseDictionaryToModel (Dictionary dict) { // T obj = default(T); obj = Activator.CreateInstance (); //根据Key值设定 Columns foreach (KeyValuePair item in dict) { PropertyInfo prop = obj.GetType().GetProperty(item.Key); if(!string.IsNullOrEmpty(item.Value)) { object value = item.Value; //Nullable 获取Model类字段的真实类型 Type itemType = Nullable.GetUnderlyingType(prop.PropertyType) == null ? prop.PropertyType : Nullable.GetUnderlyingType(prop.PropertyType); //根据Model类字段的真实类型进行转换 prop.SetValue(obj, Convert.ChangeType(value, itemType), null); } } return obj; }
posted on 2016-02-17 13:39 阅读( ...) 评论( ...)