private static int CompareProps(PropertyInfo a, PropertyInfo b) { OrderAttribute _a = (OrderAttribute)a.GetCustomAttributes(typeof(OrderAttribute), false)[0]; OrderAttribute _b = (OrderAttribute)b.GetCustomAttributes(typeof(OrderAttribute), false)[0]; return(_a.Order - _b.Order); }
public override void Serialize(Stream serializationStream, object obj) { foreach (var prop in OrderAttribute.GetSortedProperties(obj.GetType())) { var subType = prop.PropertyType; var subFormatter = _typeFormatterFactory.GetFormatter(subType); subFormatter.Serialize(serializationStream, prop.GetValue(obj, null)); } }
public override string ToString() { var result = "{"; foreach (var prop in OrderAttribute.GetSortedProperties(GetType())) { result += String.Format("{0}: {1}, ", prop.Name, prop.GetValue(this, null)); } result = result.TrimEnd(',', ' '); result += "}"; return(result); }
public override object Deserialize(Stream serializationStream, Type t) { var ret = t.GetConstructor(new Type[] {}).Invoke(new object[] {}); foreach (var prop in OrderAttribute.GetSortedProperties(t)) { var subType = prop.PropertyType; var subFormatter = _typeFormatterFactory.GetFormatter(subType); var subObj = subFormatter.Deserialize(serializationStream, subType); prop.SetValue(ret, subObj, null); } return(ret); }
public override string ToString() { var enumProp = OrderAttribute.GetPropertyByOrder(GetType(), 0); var value = enumProp.GetValue(this, null); var index = (int)value + 1; var prop = OrderAttribute.GetPropertyByOrder(GetType(), index); if (prop != null) { return(String.Format("({0}: {1})", prop.Name, prop.GetValue(this, null))); } else { return(String.Format("({0})", value)); } }
public override void Serialize(Stream serializationStream, object obj) { var typeProp = OrderAttribute.GetPropertyByOrder(obj.GetType(), 0); var enumFormatter = _typeFormatterFactory.GetFormatter(typeProp.PropertyType); var enumValue = typeProp.GetValue(obj, null); enumFormatter.Serialize(serializationStream, enumValue); var index = ((int)enumValue) + 1; var subProp = OrderAttribute.GetPropertyByOrder(obj.GetType(), index); if (subProp != null) { var subType = subProp.PropertyType; var subFormatter = _typeFormatterFactory.GetFormatter(subType); subFormatter.Serialize(serializationStream, subProp.GetValue(obj, null)); } }
public override object Deserialize(Stream serializationStream, Type t) { var ret = t.GetConstructor(new Type[] {}).Invoke(new object[] {}); var typeProp = OrderAttribute.GetPropertyByOrder(t, 0); var enumFormatter = _typeFormatterFactory.GetFormatter(typeProp.PropertyType); var enumValue = enumFormatter.Deserialize(serializationStream, typeProp.PropertyType); typeProp.SetValue(ret, enumValue, null); var index = ((int)enumValue) + 1; var prop = OrderAttribute.GetPropertyByOrder(t, index); if (prop != null) { var subType = prop.PropertyType; var subFormatter = _typeFormatterFactory.GetFormatter(subType); var subObj = subFormatter.Deserialize(serializationStream, subType); prop.SetValue(ret, subObj, null); } return(ret); }