예제 #1
0
 private void ProcessMap(object obj, SafeDictionary <string, JSON.myPropInfo> props, Dictionary <string, object> dic)
 {
     foreach (KeyValuePair <string, object> kv in dic)
     {
         myPropInfo p = props[kv.Key];
         object     o = p.getter(obj);
         Type       t = Type.GetType((string)kv.Value);
         if (t == typeof(Guid))
         {
             p.setter(obj, CreateGuid((string)o));
         }
     }
 }
예제 #2
0
 private static void ProcessMap(object obj, Dictionary <string, myPropInfo> props, Dictionary <string, object> dic)
 {
     foreach (KeyValuePair <string, object> kv in dic)
     {
         myPropInfo p = props[kv.Key];
         object     o = p.getter(obj);
         // blacklist checking
         Type t = //Type.GetType((string)kv.Value);
                  Reflection.Instance.GetTypeFromCache((string)kv.Value, true);
         if (t == typeof(Guid))
         {
             p.setter(obj, Helper.CreateGuid((string)o));
         }
     }
 }
예제 #3
0
        private object ParseDictionary(Dictionary <string, object> d)
        {
            object tn = "";

            if (d.TryGetValue("$type", out tn) == false)
            {
                return(CreateDataset(d));
            }
            Type   type     = GetTypeFromCache((string)tn);
            string typename = type.Name;
            object o        = FastCreateInstance(type);
            SafeDictionary <string, myPropInfo> props = getproperty(type, typename);

            foreach (string name in d.Keys)
            {
                if (name == "$type")
                {
                    continue;
                }
                if (name == "$map")
                {
                    ProcessMap(o, props, (Dictionary <string, object>)d[name]);
                    continue;
                }
                myPropInfo pi = props[name];
                if (pi.filled == true)
                {
                    object v = d[name];

                    if (v != null)
                    {
                        object oset = null;

                        if (pi.isInt)
                        {
                            oset = (int)CreateLong((string)v);
                        }

                        else if (pi.isLong)
                        {
                            oset = CreateLong((string)v);
                        }

                        else if (pi.isString)
                        {
                            oset = (string)v;
                        }

                        else if (pi.isBool)
                        {
                            oset = (bool)v;
                        }

                        else if (pi.isGenericType && pi.isValueType == false && pi.isDictionary == false)
                        {
                            oset = CreateGenericList((ArrayList)v, pi.pt, pi.bt);
                        }

                        else if (pi.isByteArray)
                        {
                            oset = Convert.FromBase64String((string)v);
                        }

                        else if (pi.isArray && pi.isValueType == false)
                        {
                            oset = CreateArray((ArrayList)v, pi.pt, pi.bt);
                        }

                        else if (pi.isGuid)
                        {
                            oset = CreateGuid((string)v);
                        }

                        else if (pi.isDataSet)
                        {
                            oset = CreateDataset((Dictionary <string, object>)v);
                        }

                        else if (pi.isDictionary || pi.isHashtable)
                        {
                            oset = CreateDictionary((ArrayList)v, pi.pt, pi.GenericTypes);
                        }

                        else if (pi.isEnum)
                        {
                            oset = CreateEnum(pi.pt, (string)v);
                        }

                        else if (pi.isDateTime)
                        {
                            oset = CreateDateTime((string)v);
                        }

                        else if (pi.isClass && v is Dictionary <string, object> )
                        {
                            oset = ParseDictionary((Dictionary <string, object>)v);
                        }

                        else if (pi.isValueType)
                        {
                            oset = ChangeType(v, pi.changeType);
                        }

                        else if (v is ArrayList)
                        {
                            oset = CreateArray((ArrayList)v, pi.pt, typeof(object));
                        }

                        else
                        {
                            oset = v;
                        }

                        pi.setter(o, oset);
                    }
                }
            }
            return(o);
        }