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);
        }
예제 #2
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);
        }
예제 #3
0
 public EzyBinding(
     IDictionary <Type, IEzyWriter> writerByInType,
     IDictionary <Type, IEzyReader> readerByOutType)
 {
     this.marshaller   = new EzyMarshaller(writerByInType);
     this.unmarshaller = new EzyUnmarshaller(readerByOutType);
 }
예제 #4
0
 protected override object dataToValue(
     DateTime data,
     EzyMarshaller marshaller)
 {
     return(data.Millisecond);
 }
예제 #5
0
 protected abstract object dataToValue(T data, EzyMarshaller marshaller);
예제 #6
0
 public object write(object input, EzyMarshaller marshaller)
 {
     return(dataToValue((T)input, marshaller));
 }
예제 #7
0
 protected abstract EzyArray objectToArray(T obj, EzyMarshaller marshaller);
예제 #8
0
 public object write(object input, EzyMarshaller marshaller)
 {
     return(objectToArray((T)input, marshaller));
 }
예제 #9
0
 protected abstract EzyObject objectToMap(T obj, EzyMarshaller marshaller);