/// <summary> /// Writes the custom type information. /// </summary> private static void WriteCustomTypeInfo(BinaryWriter writer, Type customType) { var raw = writer.GetRawWriter(); if (customType != null) { raw.WriteBoolean(true); var desc = writer.Marshaller.GetDescriptor(customType); if (desc.IsRegistered) { raw.WriteBoolean(true); raw.WriteInt(desc.TypeId); } else { raw.WriteBoolean(false); raw.WriteString(customType.FullName); } } else { raw.WriteBoolean(false); } }
/** <inheritdoc /> */ public void WriteBinary <T>(T obj, BinaryWriter writer) { var ctx = GetStreamingContext(writer); _serializableTypeDesc.OnSerializing(obj, ctx); var serializable = (ISerializable)obj; var objType = obj.GetType(); // Get field values and write them. var serInfo = new SerializationInfo(objType, new FormatterConverter()); serializable.GetObjectData(serInfo, ctx); var dotNetFields = WriteSerializationInfo(writer, serInfo); // Check if there is any additional information to be written. var customType = GetCustomType(serInfo, serializable); if (dotNetFields != null || writer.Marshaller.Ignite == null || customType != null) { // Set custom type flag in object header. writer.SetCustomTypeDataFlag(true); // Write additional information in raw mode. writer.GetRawWriter(); WriteFieldNames(writer, serInfo); WriteCustomTypeInfo(writer, customType); WriteDotNetFields(writer, dotNetFields); } _serializableTypeDesc.OnSerialized(obj, ctx); }