Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EntitySerializer"/> class.
 /// </summary>
 /// <param name="entityContext">
 /// The entity context.
 /// </param>
 /// <param name="binaryWriter">
 /// The binary writer.
 /// </param>
 /// <param name="root">
 /// The root object.
 /// </param>
 /// <param name="serializingEntity">
 /// The serializing entity delegate.
 /// </param>
 private EntitySerializer(EntityContext entityContext, BinaryWriter binaryWriter, object root, SerializingEntity serializingEntity)
     : base(binaryWriter)
 {
     this.entityContext = entityContext;
     this.root = root;
     this.serializingEntity = serializingEntity;
 }
Beispiel #2
0
        /// <summary>
        ///     Serialize an object.
        /// </summary>
        /// <param name="entityContext">
        ///     The entity context.
        /// </param>
        /// <param name="serializeType">
        ///     The serialize type.
        /// </param>
        /// <param name="value">
        ///     The object to serialize.
        /// </param>
        /// <param name="capacity">
        ///     The internal memory stream intial capacity.
        /// </param>
        /// <param name="write">
        ///     If <c>true</c> value will be serialized; otherwise only traversed, null will be returned.
        /// </param>
        /// <param name="serializingEntity">
        ///     The serializing entity delegate.
        /// </param>
        /// <returns>
        ///     The serialized object.
        /// </returns>
        internal static byte[] Serialize(EntityContext entityContext, Type serializeType, object value, int capacity, bool write,
                                         SerializingEntity serializingEntity)
        {
            if (write)
            {
#if HT4O_BUFFEREDBINARYWRITER
                using (var memoryStream = new WritableMemoryStream(capacity))
                {
                    using (var binaryWriter = new BufferedBinaryWriter(memoryStream, true))
                    {
                        var entitySerializer = new EntitySerializer(entityContext, binaryWriter, value, serializingEntity);
                        entitySerializer.Write(serializeType, value);
                    }

                    return(memoryStream.ToArray());
                }
#else
                using (var binaryWriter = new HeapBinaryWriter()) {
                    var entitySerializer = new EntitySerializer(entityContext, binaryWriter, value, serializingEntity);
                    entitySerializer.Write(serializeType, value);
                    return(binaryWriter.ToArray());
                }
#endif
            }

            using (var binaryWriter = new FakeBinaryWriter())
            {
                var entitySerializer = new EntitySerializer(entityContext, binaryWriter, value, serializingEntity);
                entitySerializer.Write(serializeType, value);
            }

            return(null);
        }
Beispiel #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EntitySerializer" /> class.
 /// </summary>
 /// <param name="entityContext">
 ///     The entity context.
 /// </param>
 /// <param name="binaryWriter">
 ///     The binary writer.
 /// </param>
 /// <param name="root">
 ///     The root object.
 /// </param>
 /// <param name="serializingEntity">
 ///     The serializing entity delegate.
 /// </param>
 private EntitySerializer(EntityContext entityContext, BinaryWriter binaryWriter, object root,
                          SerializingEntity serializingEntity)
     : base(binaryWriter)
 {
     this.entityContext     = entityContext;
     this.root              = root;
     this.serializingEntity = serializingEntity;
 }
Beispiel #4
0
        /// <summary>
        ///     Serialize an object.
        /// </summary>
        /// <param name="entityContext">
        ///     The entity context.
        /// </param>
        /// <param name="serializeType">
        ///     The serialize type.
        /// </param>
        /// <param name="value">
        ///     The object to serialize.
        /// </param>
        /// <param name="capacity">
        ///     The internal memory stream intial capacity.
        /// </param>
        /// <param name="serializingEntity">
        ///     The serializing entity delegate.
        /// </param>
        /// <returns>
        ///     The serialized object.
        /// </returns>
        internal static byte[] Serialize(EntityContext entityContext, Type serializeType, object value, int capacity,
                                         SerializingEntity serializingEntity)
        {
            using (var memoryStream = new MemoryStream(capacity))
            {
                using (var binaryWriter = new BufferedBinaryWriter(memoryStream))
                {
                    new EntitySerializer(entityContext, binaryWriter, value, serializingEntity).Write(serializeType,
                                                                                                      value);
                }

                return(memoryStream.ToArray());
            }
        }
Beispiel #5
0
        /// <summary>
        /// Serialize an object.
        /// </summary>
        /// <param name="entityContext">
        /// The entity context.
        /// </param>
        /// <param name="serializeType">
        /// The serialize type.
        /// </param>
        /// <param name="value">
        /// The object to serialize.
        /// </param>
        /// <param name="capacity">
        /// The internal memory stream intial capacity.
        /// </param>
        /// <param name="serializingEntity">
        /// The serializing entity delegate.
        /// </param>
        /// <returns>
        /// The serialized object.
        /// </returns>
        internal static byte[] Serialize(EntityContext entityContext, Type serializeType, object value, int capacity, SerializingEntity serializingEntity)
        {
            using (var memoryStream = new MemoryStream(capacity))
            {
                using (var binaryWriter = new BufferedBinaryWriter(memoryStream))
                {
                    new EntitySerializer(entityContext, binaryWriter, value, serializingEntity).Write(serializeType, value);
                }

                return memoryStream.ToArray();
            }
        }