-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathProgressToken.cs
79 lines (64 loc) · 2.28 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace OmniSharp.Extensions.DebugAdapter.Protocol.Models
{
[DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")]
public struct ProgressToken : IEquatable<ProgressToken>, IEquatable<long>, IEquatable<string>
{
private long? _long;
private string _string;
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;
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 override bool Equals(object obj) =>
obj is ProgressToken token &&
Equals(token);
public override int GetHashCode()
{
var hashCode = 1456509845;
hashCode = hashCode * -1521134295 + IsLong.GetHashCode();
hashCode = hashCode * -1521134295 + Long.GetHashCode();
hashCode = hashCode * -1521134295 + IsString.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(String);
return hashCode;
}
public bool Equals(ProgressToken other) =>
IsLong == other.IsLong &&
Long == other.Long &&
IsString == other.IsString &&
String == other.String;
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;
}
}