-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSimpleLocation.cs
34 lines (29 loc) · 1.06 KB
/
SimpleLocation.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
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace Architect.DomainModeling.Generator.Common;
/// <summary>
/// Represents a <see cref="Location"/> as a simple, serializable structure.
/// </summary>
internal sealed record class SimpleLocation
{
public string FilePath { get; }
public TextSpan TextSpan { get; }
public LinePositionSpan LineSpan { get; }
public SimpleLocation(Location location)
{
var lineSpan = location.GetLineSpan();
this.FilePath = lineSpan.Path;
this.TextSpan = location.SourceSpan;
this.LineSpan = lineSpan.Span;
}
public SimpleLocation(string filePath, TextSpan textSpan, LinePositionSpan lineSpan)
{
this.FilePath = filePath;
this.TextSpan = textSpan;
this.LineSpan = lineSpan;
}
#nullable disable
public static implicit operator SimpleLocation(Location location) => location is null ? null : new SimpleLocation(location);
public static implicit operator Location(SimpleLocation location) => location is null ? null : Location.Create(location.FilePath, location.TextSpan, location.LineSpan);
#nullable enable
}