Beispiel #1
0
        /** <inheritdoc /> */
        void IBinarySerializerInternal.WriteBinary <T>(T obj, BinaryWriter writer)
        {
            Debug.Assert(_wActions != null);
            Debug.Assert(writer != null);

            var ctx = GetStreamingContext(writer);

            _serializableDescriptor.OnSerializing(obj, ctx);

            foreach (var action in _wActions)
            {
                action(obj, writer);
            }

            _serializableDescriptor.OnSerialized(obj, ctx);
        }
Beispiel #2
0
        /** <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);
        }