Пример #1
0
        public Dictionary <K, V> toMap <K, V>(EzyObject obj)
        {
            Dictionary <K, V> answer = new Dictionary <K, V>();

            foreach (Object key in obj.keys())
            {
                Object         value       = obj.get <Object>(key);
                Object         skey        = key;
                EzyArrayToList arrayToList = EzyArrayToList.getInstance();
                if (key is EzyArray)
                {
                    skey = arrayToList.toList <object>((EzyArray)key);
                }
                else if (key is EzyObject)
                {
                    skey = toMap <object, object>((EzyObject)key);
                }
                Object svalue = value;
                if (value != null)
                {
                    if (value is EzyArray)
                    {
                        svalue = arrayToList.toList <object>((EzyArray)value);
                    }
                    if (value is EzyObject)
                    {
                        svalue = toMap <object, object>((EzyObject)value);
                    }
                }
                answer[(K)skey] = (V)svalue;
            }
            return(answer);
        }
Пример #2
0
        public IDictionary <K, V> unmarshallDict <K, V>(EzyObject obj)
        {
            IDictionary <K, V> answer = new Dictionary <K, V>();

            foreach (object key in obj.keys())
            {
                answer[unmarshall <K>(key)] = unmarshall <V>(obj.get <V>(key));
            }
            return(answer);
        }
        protected byte[] parseObject(EzyObject obj)
        {
            int index = 1;
            int size  = obj.size();

            byte[][] bytess = new byte[size * 2 + 1][];
            bytess[0] = parseMapSize(size);
            foreach (Object key in obj.keys())
            {
                bytess[index++] = serialize(key);
                bytess[index++] = serialize(obj.get <Object>(key));
            }
            return(EzyBytes.merge(bytess));
        }
Пример #4
0
 public object unmarshallByOutType(object input, Type outType)
 {
     if (input == null)
     {
         return(null);
     }
     if (readerByOutType.ContainsKey(outType))
     {
         IEzyReader reader = readerByOutType[outType];
         return(reader.read(input, this));
     }
     if (outType.IsGenericType)
     {
         if (typeof(IDictionary).IsAssignableFrom(outType) ||
             typeof(IDictionary <,>) == outType.GetGenericTypeDefinition())
         {
             Type        dictType    = typeof(Dictionary <,>);
             Type        constructed = dictType.MakeGenericType(outType.GetGenericArguments());
             IDictionary answer      = (IDictionary)Activator.CreateInstance(constructed);
             EzyObject   obj         = (EzyObject)input;
             Type        keyType     = outType.GetGenericArguments()[0];
             Type        valueType   = outType.GetGenericArguments()[1];
             foreach (object key in obj.keys())
             {
                 answer[unmarshallByOutType(key, keyType)] =
                     unmarshallByOutType(obj.getByOutType(key, valueType), valueType);
             }
             return(answer);
         }
         else if (typeof(IList).IsAssignableFrom(outType) ||
                  typeof(IList <>) == outType.GetGenericTypeDefinition())
         {
             Type     listType    = typeof(List <>);
             Type     constructed = listType.MakeGenericType(outType.GetGenericArguments());
             IList    answer      = (IList)Activator.CreateInstance(constructed);
             EzyArray array       = (EzyArray)input;
             Type     valueType   = outType.GetGenericArguments()[0];
             for (int i = 0; i < array.size(); ++i)
             {
                 Object rawValue = array.getByOutType(i, valueType);
                 Object value    = unmarshallByOutType(rawValue, valueType);
                 answer.Add(value);
             }
             return(answer);
         }
     }
     return(input);
 }