예제 #1
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            IList list = ClassHelper.CreateListInstance(type);

            foreach (object obj in dictionary.Values)
            {
                var items = obj as IEnumerable <KeyValuePair <string, object> >;
                if (items == null || !items.Any())
                {
                    continue;
                }
                object model = ClassHelper.CreateInstance(type);
                foreach (var item in items)
                {
                    KeyValuePair <string, object> detail = (KeyValuePair <string, object>)item;
                    string       name         = detail.Key;
                    PropertyInfo propertyInfo = type.GetProperty(name);
                    if (string.IsNullOrEmpty(name) || propertyInfo == null)
                    {
                        continue;
                    }
                    //ClassHelper.SetPropertyValue(model, name, detail.Value);
                    propertyInfo.SetValue(model, SafeConverter.SafeToObject(propertyInfo.PropertyType, detail.Value), null);
                }
                list.Add(model);
            }
            return(list);
        }