[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/phxnsharp/ClearScript/master/ClearScript/StringDocument.cs [Back]  [Original]

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.IO;
using System.Text;

namespace Microsoft.ClearScript
{
    /// 
    /// Provides an in-memory  implementation for a text document.
    /// 
    public class StringDocument : Document
    {
        private readonly DocumentInfo info;
        private readonly byte[] contents;

        /// 
        /// Initializes a new  instance.
        /// 
        /// A structure containing meta-information for the document.
        /// A string containing the document's contents.
        public StringDocument(DocumentInfo info, string contents)
        {
            this.info = info;
            this.contents = Encoding.UTF8.GetBytes(contents);
        }

        #region Document overrides

        /// 
        /// Gets a structure containing meta-information for the document.
        /// 
        public override DocumentInfo Info
        {
            get { return info; }
        }

        /// 
        /// Gets a stream that provides read access to the document.
        /// 
        /// 
        /// The  implementation of this property returns a
        ///  instance.
        /// 
        public override Stream Contents
        {
            get { return new MemoryStream(contents, false); }
        }

        /// 
        /// Gets the document's character encoding.
        /// 
        /// 
        ///  instances return  for this property.
        /// 
        public override Encoding Encoding
        {
            get { return Encoding.UTF8; }
        }

        #endregion
    }
}

Web Proxy Viewer  |  New URL  |  Original Page