示例#1
0
 private JSON.GenericSetter GetSetter(PropertyInfo prop)
 {
     if (this._settercache.ContainsKey(prop))
     {
         return(this._settercache[prop]);
     }
     JSON.GenericSetter setMethod = JSON.CreateSetMethod(prop);
     this._settercache.Add(prop, setMethod);
     return(setMethod);
 }
示例#2
0
        private object ParseDictionary(Dictionary <string, object> d)
        {
            string typename      = string.Concat(d["$type"]);
            Type   typeFromCache = this.GetTypeFromCache(typename);
            object obj           = Activator.CreateInstance(typeFromCache);

            foreach (string current in d.Keys)
            {
                PropertyInfo propertyInfo = this.getproperty(typeFromCache, current);
                if (propertyInfo != null)
                {
                    object obj2 = d[current];
                    if (obj2 != null)
                    {
                        Type   propertyType = propertyInfo.PropertyType;
                        object @interface   = propertyType.GetInterface("IDictionary");
                        object value;
                        if (propertyType.IsGenericType && !propertyType.IsValueType && @interface == null)
                        {
                            IList list = (IList)Activator.CreateInstance(propertyType);
                            foreach (object current2 in ((ArrayList)obj2))
                            {
                                list.Add(this.ParseDictionary((Dictionary <string, object>)current2));
                            }
                            value = list;
                        }
                        else if (propertyType == typeof(byte[]))
                        {
                            value = Convert.FromBase64String((string)obj2);
                        }
                        else if (propertyType.IsArray && !propertyType.IsValueType)
                        {
                            ArrayList arrayList = new ArrayList();
                            foreach (object current3 in ((ArrayList)obj2))
                            {
                                arrayList.Add(this.ParseDictionary((Dictionary <string, object>)current3));
                            }
                            value = arrayList.ToArray(propertyInfo.PropertyType.GetElementType());
                        }
                        else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?))
                        {
                            value = new Guid(string.Concat(obj2));
                        }
                        else if (propertyType == typeof(DataSet))
                        {
                            value = this.CreateDataset((Dictionary <string, object>)obj2);
                        }
                        else if (propertyType == typeof(Hashtable))
                        {
                            value = this.CreateDictionary((ArrayList)obj2, propertyType);
                        }
                        else if (@interface != null)
                        {
                            value = this.CreateDictionary((ArrayList)obj2, propertyType);
                        }
                        else
                        {
                            value = this.ChangeType(obj2, propertyType);
                        }
                        JSON.GenericSetter setter = this.GetSetter(propertyInfo);
                        setter(obj, value);
                    }
                }
            }
            return(obj);
        }