[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/ddunkin/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 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)
        {
            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; }

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

        /// 
        /// Gets the document's character encoding.
        /// 
        /// 
        ///  instances return  for this property.
        /// 
        public override Encoding Encoding => Encoding.UTF8;

        #endregion
    }
}

Web Proxy Viewer  |  New URL  |  Original Page