Exemple #1
0
        protected override EzyObject objectToMap(T obj, EzyMarshaller marshaller)
        {
            EzyObject map = EzyEntityFactory.newObject();

            foreach (PropertyInfo property in objectType.GetProperties())
            {
                string   key  = null;
                EzyValue anno = property.GetCustomAttribute <EzyValue>();
                if (anno != null)
                {
                    key = anno.name;
                }
                else
                {
                    key = property.Name.Length <= 1
                        ? char.ToLower(property.Name[0]).ToString()
                        : char.ToLower(property.Name[0]) + property.Name.Substring(1);
                }
                object rawValue = property.GetValue(obj);
                object value    = rawValue != null?marshaller.marshall <object>(rawValue) : null;

                map.put(key, value);
            }
            return(map);
        }
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);
 }