| | |
| | | { |
| | | 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 (!dic.TryGetValue(property.Name, out value)) |
| | | if (!upperDic.TryGetValue(property.Name.ToUpper(), out value)) |
| | | { |
| | | if (!dic.TryGetValue(property.Name.FirstLetterToUpper(), out value)) |
| | | { |
| | | if (!dic.TryGetValue(property.Name.FirstLetterToLower(), out value)) |
| | | { |
| | | continue; |
| | | } |
| | | } |
| | | }; |
| | | continue; |
| | | } |
| | | property.SetValue(model, value?.ToString().ChangeType(property.PropertyType)); |
| | | } |
| | | return model; |