hutongqing
2024-08-21 b5bc0d6eb2d2e55ea830a1b286252b9754cbf8e9
WIDESEAWCS_Server/WIDESEAWCS_Core/Helper/ObjectExtension.cs
@@ -9,18 +9,14 @@
{
    public static class ObjectExtension
    {
        public static IEnumerable<T> DicToIEnumerable<T>(this List<Dictionary<string, object>> dicList)
        public static List<T> DicToIEnumerable<T>(this List<Dictionary<string, object>> dicList)
        {
            List<T> list = new List<T>();
            foreach (Dictionary<string, object> dic in dicList)
            {
                T model = Activator.CreateInstance<T>();
                foreach (PropertyInfo property in model.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
                {
                    if (!dic.TryGetValue(property.Name, out object value)) continue;
                    property.SetValue(model, value?.ToString().ChangeType(property.PropertyType), null);
                }
                yield return model;
                list.Add(dic.DicToModel<T>());
            }
            return list;
        }
        public static T DicToModel<T>(this Dictionary<string, object> dic)
@@ -30,7 +26,7 @@
            foreach (var property in propertyInfos)
            {
                object value = null;
                if (!dic.TryGetValue(property.Name, out value))
                if (!dic.TryGetValue(property.Name, out value))
                {
                    if (!dic.TryGetValue(property.Name.FirstLetterToUpper(), out value))
                    {