/
TextAndVersion.cs
71 lines (62 loc) · 2.67 KB
/
TextAndVersion.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
{
/// <summary>
/// A class that represents both a source text and its version stamp.
/// </summary>
public sealed class TextAndVersion
{
/// <summary>
/// The source text.
/// </summary>
public SourceText Text { get; }
/// <summary>
/// The version of the source text
/// </summary>
public VersionStamp Version { get; }
/// <summary>
/// An optional file path that identifies the origin of the source text. Empty if not available.
/// </summary>
public string FilePath { get; }
/// <summary>
/// If an error occurred while loading the text the corresponding diagnostic, otherwise null.
/// </summary>
internal Diagnostic? LoadDiagnostic { get; }
private TextAndVersion(SourceText text, VersionStamp version, string? filePath, Diagnostic? loadDiagnostic)
{
Text = text;
Version = version;
FilePath = filePath ?? string.Empty;
LoadDiagnostic = loadDiagnostic;
}
/// <summary>
/// Create a new <see cref="TextAndVersion"/> instance.
/// </summary>
/// <param name="text">The text</param>
/// <param name="version">The version</param>
/// <param name="filePath">An optional file path that identifies the original of the source text.</param>
/// <returns></returns>
public static TextAndVersion Create(SourceText text, VersionStamp version, string? filePath = null)
=> Create(text, version, filePath, loadDiagnostic: null);
/// <summary>
/// Create a new <see cref="TextAndVersion"/> instance.
/// </summary>
/// <param name="text">The text</param>
/// <param name="version">The version</param>
/// <param name="filePath">An optional file path that identifies the original of the source text.</param>
/// <param name="loadDiagnostic">Diagnostic describing failure to load the source text.</param>
/// <returns></returns>
internal static TextAndVersion Create(SourceText text, VersionStamp version, string? filePath, Diagnostic? loadDiagnostic)
{
if (text == null)
{
throw new ArgumentNullException(nameof(text));
}
return new TextAndVersion(text, version, filePath, loadDiagnostic);
}
}
}