blob: 67de693ba93287e6249c482f9e43360df8788f10 (
plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//
namespace Microsoft.VisualStudio.Text
{
using System;
/// <summary>
/// Describes a span in a specific <see cref="ITextImageVersion"/>.
/// </summary>
public struct VersionedSpan : IEquatable<VersionedSpan>
{
public readonly ITextImageVersion Version;
public readonly Span Span;
public readonly static VersionedSpan Invalid = new VersionedSpan();
public VersionedSpan(ITextImageVersion version, Span span)
{
if (version == null)
{
throw new ArgumentNullException(nameof(version));
}
if (span.End > version.Length)
{
throw new ArgumentOutOfRangeException(nameof(span));
}
this.Version = version;
this.Span = span;
}
public static implicit operator Span(VersionedSpan span)
{
return span.Span;
}
public VersionedSpan TranslateTo(ITextImageVersion other, SpanTrackingMode mode)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
return new VersionedSpan(other, other.TrackTo(this, mode));
}
public override int GetHashCode()
{
return (this.Version != null) ? (this.Span.GetHashCode() ^ this.Version.GetHashCode()) : 0;
}
public override bool Equals(object obj)
{
if (obj is VersionedSpan)
{
var other = (VersionedSpan)obj;
return this.Equals(other);
}
return false;
}
public bool Equals(VersionedSpan other)
{
return (other.Version == this.Version) && (other.Span == this.Span);
}
public static bool operator ==(VersionedSpan left, VersionedSpan right)
{
return left.Equals(right);
}
public static bool operator !=(VersionedSpan left, VersionedSpan right)
{
return !left.Equals(right);
}
public override string ToString()
{
return (this.Version == null)
? nameof(Invalid)
: string.Format(System.Globalization.CultureInfo.CurrentCulture, "v{1}_{2}",
this.Version.VersionNumber,
this.Span);
}
}
}
|