huangxiaoqiang
2025-06-12 a407d85032a312cd93513d24e1bd34219e3aa3c9
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/ObjectExtension.cs
@@ -21,6 +21,22 @@
        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)
@@ -35,10 +51,12 @@
                            continue;
                        }
                    }
                };
                }
                ;
                property.SetValue(model, value?.ToString().ChangeType(property.PropertyType));
            }
            return model;
        }
    }
}