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