/// <summary> /// Serialize an object. /// </summary> /// <param name="obj">The object.</param> /// <param name="context">TL serialization context.</param> /// <param name="modeOverride">Serialization mode override.</param> /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception> public static void Serialize(object obj, TLSerializationContext context, TLSerializationMode?modeOverride = null) { var objType = obj.GetType(); ITLSerializer serializer = context.Rig.GetSerializerByObjectType(objType); if (serializer == null) { throw new TLSerializerNotFoundException(string.Format("There is no serializer for a type: '{0}'.", objType.FullName)); } serializer.Write(obj, context, modeOverride); }
protected override void WriteBody(object obj, TLSerializationContext context) { for (int i = 0; i < _properties.Length; i++) { TLPropertyInfo tlPropertyInfo = _properties[i]; PropertyInfo propertyInfo = tlPropertyInfo.PropertyInfo; Type propType = propertyInfo.PropertyType; object propertyValue = propertyInfo.GetValue(obj); ITLSerializer tlSerializer = context.Rig.GetSerializerByObjectType(propType); if (tlSerializer is ITLVectorSerializer) { var vectorSerializer = tlSerializer as ITLVectorSerializer; TLSerializationMode?itemsSerializationModeOverride = GetVectorItemsSerializationModeOverride(vectorSerializer, propertyInfo, context); vectorSerializer.Write(propertyValue, context, tlPropertyInfo.SerializationModeOverride, itemsSerializationModeOverride); } else { tlSerializer.Write(propertyValue, context, tlPropertyInfo.SerializationModeOverride); } } }
protected override void WriteValue(object propertyValue, TLSerializationContext context) { _serializer.Write(propertyValue, context, TLPropertyInfo.SerializationModeOverride); }