protected override EzyArray objectToArray(T obj, EzyMarshaller marshaller)
        {
            int count = 0;
            SortedDictionary <int, object> valueByIndex = new SortedDictionary <int, object>();

            foreach (PropertyInfo property in objectType.GetProperties())
            {
                EzyValue anno     = property.GetCustomAttribute <EzyValue>();
                int      index    = anno != null ? anno.index : count;
                object   rawValue = property.GetValue(obj);
                object   value    = rawValue != null?marshaller.marshall <object>(rawValue) : null;

                valueByIndex[index] = value;
                ++count;
            }
            EzyArray array = EzyEntityFactory.newArray();

            for (int i = 0; i < count; ++i)
            {
                object value = null;
                if (valueByIndex.ContainsKey(i))
                {
                    value = valueByIndex[i];
                }
                array.add(value);
            }
            return(array);
        }
Exemple #2
0
 public object marshallByInType(object input, Type inType)
 {
     if (input == null)
     {
         return(null);
     }
     if (writerByInType.ContainsKey(inType))
     {
         IEzyWriter writer = writerByInType[inType];
         return(writer.write(input, this));
     }
     if (typeof(IDictionary).IsAssignableFrom(inType))
     {
         EzyObject   answer    = EzyEntityFactory.newObject();
         IDictionary dict      = (IDictionary)(input);
         Type        keyType   = inType.GetGenericArguments()[0];
         Type        valueType = inType.GetGenericArguments()[1];
         foreach (DictionaryEntry entry in dict)
         {
             answer.put(
                 marshallByInType(entry.Key, keyType),
                 marshallByInType(entry.Value, valueType));
         }
         return(answer);
     }
     else if (typeof(IList).IsAssignableFrom(inType))
     {
         EzyArray answer    = EzyEntityFactory.newArray();
         IList    list      = (IList)(input);
         Type     valueType = inType.GetGenericArguments()[0];
         foreach (Object value in list)
         {
             answer.add(marshallByInType(value, valueType));
         }
         return(answer);
     }
     return(input);
 }
Exemple #3
0
 protected Object transformNonNullValue(Object value)
 {
     if (value is IDictionary)
     {
         IDictionary dictionary = (IDictionary)value;
         EzyObject   obj        = EzyEntityFactory.newObject();
         foreach (DictionaryEntry entry in dictionary)
         {
             obj.put(transform(entry.Key), transform(entry.Value));
         }
         return(obj);
     }
     if (value is ICollection)
     {
         IEnumerable collection = (IEnumerable)value;
         EzyArray    array      = EzyEntityFactory.newArray();
         foreach (Object item in collection)
         {
             array.add(transform(item));
         }
         return(array);
     }
     return(value);
 }