forked from OmniSharp/csharp-language-server-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooleanOr.cs
59 lines (55 loc) · 1.38 KB
/
BooleanOr.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
namespace OmniSharp.Extensions.LanguageServer.Protocol.Models
{
public class BooleanOr<T>
{
private T _value;
private bool? _bool;
public BooleanOr(T value)
{
_value = value;
_bool = null;
}
public BooleanOr(bool value)
{
_value = default;
_bool = value;
}
public bool IsValue => this._value != null;
public T Value
{
get { return this._value; }
set
{
this._value = value;
this._bool = null;
}
}
public bool IsBool => this._bool.HasValue;
public bool Bool
{
get { return this._bool.HasValue && this._bool.Value; }
set
{
this.Value = default;
this._bool = value;
}
}
public object RawValue
{
get
{
if (IsBool) return Bool;
if (IsValue) return Value;
return null;
}
}
public static implicit operator BooleanOr<T>(T value)
{
return value != null ? new BooleanOr<T>(value) : null;
}
public static implicit operator BooleanOr<T>(bool value)
{
return new BooleanOr<T>(value);
}
}
}