/// <summary> /// Serializes the data in the specified object to the stream. /// </summary> /// <param name="obj">The object to be serialized.</param> /// <param name="writer">The location where the data will be written.</param> public void SerializeData(object obj, BinaryWriter writer) { onSerializing?.Invoke(obj, null); foreach (var pair in serializableFields) { var sfield = pair.Value; try { FastSerializationManager.WriteValue(writer, sfield.targetType, sfield. GetValue(obj)); } catch (Exception e) { Debug.LogErrorFormat("Error while serializing field {0} on template {1}: {2}", sfield.field.Name, targetType.Name, e.ToString()); throw; } } foreach (var pair in serializableProperties) { var sprop = pair.Value; try { FastSerializationManager.WriteValue(writer, sprop.targetType, sprop. GetValue(obj)); } catch (Exception e) { Debug.LogErrorFormat("Error while serializing property {0} on template {1}: {2}", sprop.property.Name, targetType.Name, e.ToString()); throw; } } customSerialize?.Invoke(obj, new object[] { writer }); onSerialized?.Invoke(obj, null); }
/// <summary> /// Applied before WriteValue runs. /// </summary> internal static bool Prefix(BinaryWriter writer, TypeInfo type_info, object value) { FastSerializationManager.WriteValue(writer, type_info, value); return(false); }