Esempio n. 1
0
            internal StreamAsIBinaryStream( Stream stream )
            {
                if( stream.NullReference() )
                    throw new ArgumentNullException().StoreFileLine();

                if( !stream.CanRead )
                    throw new ArgumentException("Stream not readable!").StoreFileLine();

                if( !stream.CanWrite )
                    throw new ArgumentException("Stream not writable!").StoreFileLine();

                if( !stream.CanSeek )
                    throw new ArgumentException("Stream not seekable!").StoreFileLine();

                this.stream = stream;
                this.reader = new BinaryStreamReaderLE(this.stream);
                this.writer = new BinaryStreamWriterLE(this.stream);
            }
Esempio n. 2
0
            /// <summary>
            /// Called when the object is being disposed of. Inheritors must call base.OnDispose to be properly disposed.
            /// </summary>
            /// <param name="disposing">If set to <c>true</c>, release both managed and unmanaged resources; otherwise release only the unmanaged resources.</param>
            protected override void OnDispose( bool disposing )
            {
                if( disposing )
                {
                    //// dispose-only (i.e. non-finalizable) logic
                    //// (managed, disposable resources you own)

                    if( this.stream.NotNullReference() )
                    {
                        this.stream.Dispose();
                        this.stream = null;
                    }
                }

                //// shared cleanup logic
                //// (unmanaged resources)
                this.reader = null;
                this.writer = null;

                base.OnDispose(disposing);
            }
        /// <summary>
        /// Returns the writer of the value.
        /// If possible, a new reader should not be created.
        /// </summary>
        /// <returns>The writer of the value.</returns>
        protected override IBinaryWriter OpenBinaryWriter()
        {
            if( this.memoryStream.NullReference() )
            {
                this.memoryStream = new System.IO.MemoryStream();
                this.binaryWriter = new BinaryStreamWriterLE(this.memoryStream);
            }

            return this.binaryWriter;
        }