| | |
| | | |
| | | public static T DicToModel<T>(this Dictionary<string, object> dic) |
| | | { |
| | | //T model = Activator.CreateInstance<T>(); |
| | | //PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance); |
| | | |
| | | //Dictionary<string, object> upperDic = dic.ToDictionary(k => k.Key.ToUpper(), v => v.Value); |
| | | |
| | | //foreach (var property in propertyInfos) |
| | | //{ |
| | | // object value = null; |
| | | // if (!upperDic.TryGetValue(property.Name.ToUpper(), out value)) |
| | | // { |
| | | // continue; |
| | | // } |
| | | // property.SetValue(model, value?.ToString().ChangeType(property.PropertyType)); |
| | | //} |
| | | //return model; |
| | | |
| | | T model = Activator.CreateInstance<T>(); |
| | | PropertyInfo[] propertyInfos = typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance); |
| | | foreach (var property in propertyInfos) |
| | |
| | | continue; |
| | | } |
| | | } |
| | | }; |
| | | } |
| | | ; |
| | | property.SetValue(model, value?.ToString().ChangeType(property.PropertyType)); |
| | | } |
| | | return model; |
| | | |
| | | } |
| | | } |
| | | } |