public static T ToObject()

in Darabonba/Model.cs [24:51]


        public static T ToObject<T>(Dictionary<string, object> dict, T obj) where T : class
        {
            if (dict == null)
            {
                return null;
            }
            Type type = obj.GetType();
            PropertyInfo[] properties = type.GetProperties();
            //Properties Map
            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo p = properties[i];
                var propertyType = p.PropertyType;
                NameInMapAttribute attribute = p.GetCustomAttribute(typeof(NameInMapAttribute)) as NameInMapAttribute;
                string realName = attribute == null ? p.Name : attribute.Name;
                if (dict.ContainsKey(realName))
                {
                    var value = dict[realName];
                    if (value == null)
                    {
                        p.SetValue(obj, value);
                        continue;
                    }
                    p.SetValue(obj, MapObj(propertyType, value));
                }
            }
            return obj;
        }