-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathProgressToken.cs
65 lines (52 loc) · 1.71 KB
/
ProgressToken.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
using System;
using System.Diagnostics;
namespace OmniSharp.Extensions.DebugAdapter.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public record ProgressToken : IEquatable<long>, IEquatable<string>
{
private long? _long;
private string? _string;
public ProgressToken(Guid value)
{
_string = value.ToString();
_long = null;
}
public ProgressToken(long value)
{
_long = value;
_string = null;
}
public ProgressToken(string value)
{
_long = null;
_string = value;
}
public bool IsLong => _long.HasValue;
public long Long
{
get => _long ?? 0;
set {
_string = null;
_long = value;
}
}
public bool IsString => _string != null;
public string String
{
get => _string ?? string.Empty;
set {
_string = value;
_long = null;
}
}
public static implicit operator ProgressToken(long value) => new ProgressToken(value);
public static implicit operator ProgressToken(string value) => new ProgressToken(value);
public static implicit operator ProgressToken(Guid value) => new ProgressToken(value);
public bool Equals(long other) => IsLong && Long == other;
public bool Equals(string other) => IsString && String == other;
private string DebuggerDisplay => IsString ? String : IsLong ? Long.ToString() : "";
/// <inheritdoc />
public override string ToString() => DebuggerDisplay;
}
}