BamlStream.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / MS / Internal / AppModel / BamlStream.cs / 2 / BamlStream.cs

                            //------------------------------------------------------------------------------ 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// Description: 
// BamlStream is stream wrapper, It contains a raw baml stream and 
// the assembly which hosts the baml stream.
// 
// History:
//  05/17/2006: [....]: Initial creation.
//
//----------------------------------------------------------------------------- 

using System; 
using System.IO; 
using System.Reflection;
using System.Resources; 
using System.Globalization;
using System.Runtime.Remoting;
using System.Windows.Markup;
using System.Security; 

namespace MS.Internal.AppModel 
{ 

    //  
    // BamlStream is stream wrapper, It contains a raw baml stream and
    // the assembly which hosts the baml stream.
    // 
    internal class BamlStream : Stream, IStreamInfo 
    {
        //----------------------------------------------------- 
        // 
        //  Constructor
        // 
        //-----------------------------------------------------

        #region Constructor
 
        /// 
        ///     Critical - because it stores the assembly passed in to it the _assembly field that is marked 
        ///                SecurityCriticalDataForSet, and this field is used by the BamlRecordReader to 
        ///                allow legitimate internal types in Partial Trust.
        ///  
        [SecurityCritical]
        internal BamlStream(Stream stream, Assembly assembly)
        {
            _assembly.Value = assembly; 
            _stream = stream;
        } 
        #endregion 

        //------------------------------------------------------ 
        //
        //  Internal Property
        //
        //----------------------------------------------------- 

        #region Internal Property 
 
        //
        // Assembly which contains the Baml stream data. 
        //
        Assembly IStreamInfo.Assembly
        {
            get { return _assembly.Value; } 
        }
 
        #endregion 

        //------------------------------------------------------ 
        //
        //  Overridden Properties
        //
        //------------------------------------------------------ 

        #region Overridden Properties 
 
        // 
        // Overridden CanRead Property 
        // 
        public override bool CanRead
        {
            get { return _stream.CanRead; } 
        }
 
        //  
        // Overridden CanSeek Property
        //  
        public override bool CanSeek
        {
            get { return _stream.CanSeek; }
        } 

        //  
        // Overridden CanWrite Property 
        // 
        public override bool CanWrite 
        {
            get { return _stream.CanWrite; }
        }
 
        // 
        // Overridden Length Property 
        //  
        public override long Length
        { 
            get { return _stream.Length;  }
        }

        //  
        // Overridden Position Property
        //  
        public override long Position 
        {
            get {  return _stream.Position;  } 
            set {  _stream.Position = value; }
        }

        #endregion Overridden Properties 

        #region Overridden Public Methods 
 
        // 
        // Overridden BeginRead method 
        // 
        public override IAsyncResult BeginRead(
            byte[] buffer,
            int offset, 
            int count,
            AsyncCallback callback, 
            object state 
            )
        { 
            return _stream.BeginRead(buffer, offset, count, callback, state);
        }

        //  
        // Overridden BeginWrite method
        //  
        public override IAsyncResult BeginWrite( 
            byte[] buffer,
            int offset, 
            int count,
            AsyncCallback callback,
            object state
            ) 
        {
            return _stream.BeginWrite(buffer, offset, count, callback, state); 
        } 

        //  
        // Overridden Close method
        // 
        public override void Close()
        { 
            _stream.Close();
        } 
 
        // 
        // Overridden EndRead method 
        // 
        public override int EndRead(
            IAsyncResult asyncResult
            ) 
        {
            return _stream.EndRead(asyncResult); 
        } 

        //  
        // Overridden EndWrite method
        // 
        public override void EndWrite(
            IAsyncResult asyncResult 
            )
        { 
            _stream.EndWrite(asyncResult); 
        }
 
        // 
        // Overridden Equals method
        // 
        public override bool Equals( 
            object obj
            ) 
        { 
            return _stream.Equals(obj);
        } 

        // 
        // Overridden Flush method
        //  
        public override void Flush()
        { 
            _stream.Flush(); 
        }
 
        // 
        // Overridden GetHashCode method
        // 
        public override int GetHashCode() 
        {
            return _stream.GetHashCode(); 
        } 

        //  
        // Overridden Read method
        // 
        public override int Read(
            byte[] buffer, 
            int offset,
            int count 
            ) 
        {
            return _stream.Read(buffer, offset, count); 
        }

        // 
        // Overridden ReadByte method 
        // 
        public override int ReadByte() 
        { 
            return _stream.ReadByte();
        } 

        // 
        // Overridden Seek method
        //  
        public override long Seek(
            long offset, 
            SeekOrigin origin 
            )
        { 
            return _stream.Seek(offset, origin);
        }

        //  
        // Overridden SetLength method
        //  
        public override void SetLength( 
            long value
            ) 
        {
            _stream.SetLength(value);
        }
 
        // 
        // Overridden ToString method 
        //  
        public override string ToString()
        { 
            return _stream.ToString();
        }

        //  
        // Overridden Write method
        //  
        public override void Write( 
            byte[] buffer,
            int offset, 
            int count
            )
        {
            _stream.Write(buffer, offset, count); 
        }
 
        //  
        // Overridden WriteByte method
        //  
        public override void WriteByte(
            byte value
            )
        { 
            _stream.WriteByte(value);
        } 
 
        #endregion Overridden Public Methods
 
        //-----------------------------------------------------
        //
        //  Private Fields
        // 
        //------------------------------------------------------
 
        #region Private Members 

        private SecurityCriticalDataForSet _assembly; 
        private Stream   _stream = null;

        #endregion Private Members
    } 
}
 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK