-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathStringDocument.cs
More file actions
56 lines (48 loc) · 1.89 KB
/
StringDocument.cs
File metadata and controls
56 lines (48 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System.IO;
using System.Text;
namespace Microsoft.ClearScript
{
/// <summary>
/// Provides an in-memory <c><see cref="Document"/></c> implementation for a text document.
/// </summary>
public class StringDocument : Document
{
/// <summary>
/// Initializes a new <c><see cref="StringDocument"/></c> instance.
/// </summary>
/// <param name="info">A structure containing meta-information for the document.</param>
/// <param name="contents">A string containing the document's contents.</param>
public StringDocument(DocumentInfo info, string contents)
{
Info = info;
StringContents = contents;
}
/// <summary>
/// Gets the document's contents as a string.
/// </summary>
public string StringContents { get; }
#region Document overrides
/// <summary>
/// Gets a structure containing meta-information for the document.
/// </summary>
public override DocumentInfo Info { get; }
/// <summary>
/// Gets a stream that provides read access to the document.
/// </summary>
/// <remarks>
/// The <c><see cref="StringDocument"/></c> implementation of this property returns a
/// <c><see cref="MemoryStream"/></c> instance.
/// </remarks>
public override Stream Contents => new MemoryStream(Encoding.GetBytes(StringContents), false);
/// <summary>
/// Gets the document's character encoding.
/// </summary>
/// <remarks>
/// <c><see cref="StringDocument"/></c> instances return <c><see cref="System.Text.Encoding.UTF8"/></c> for this property.
/// </remarks>
public override Encoding Encoding => Encoding.UTF8;
#endregion
}
}