push
coveralls.net
1381 of 1456 relevant lines covered (94.85%)
4.38 hits per line
1 |
namespace Beefeater |
|
2 |
{ |
|
3 |
public struct Option<T> |
|
4 |
{ |
|
5 |
private readonly T _value;
|
|
6 |
|
|
7 |
public Option(T value) : this() |
|
8 |
{ |
|
9 |
if (value != null)
|
2✔ |
10 |
{ |
2✔ |
11 |
HasValue = true;
|
2✔ |
12 |
_value = value; |
|
13 |
} |
|
14 |
} |
18✔ |
15 |
|
18✔ |
16 |
public T ValueOr(T fallbackValue)
|
10✔ |
17 |
{ |
10✔ |
18 |
return !HasValue ? fallbackValue : _value;
|
|
19 |
} |
|
20 |
|
8✔ |
21 |
public static Option<T> None => new Option<T>(); |
10✔ |
22 |
|
|
23 |
public bool HasValue { get; } |
|
24 |
|
|
25 |
public static implicit operator Option<T>(T item) |
|
26 |
{ |
97✔ |
27 |
return new Option<T>(item); |
97✔ |
28 |
} |
97✔ |
29 |
|
73✔ |
30 |
public static explicit operator T(Option<T> option) |
73✔ |
31 |
{ |
73✔ |
32 |
if (option.HasValue)
|
73✔ |
33 |
{ |
97✔ |
34 |
return option._value;
|
|
35 |
} |
30✔ |
36 |
|
|
37 |
throw new PanicException(); |
124✔ |
38 |
} |
|
39 |
} |
|
40 |
} |
× |