Skip to content

Commit d15ec73

Browse files
update DynamicTryGet to use MustSet
1 parent 2a11b5f commit d15ec73

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

Helpers/MustSet.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public struct MustSet<T>
44
{
5-
private bool _set;
5+
private readonly bool _set;
66

77
public T Value
88
{
@@ -12,13 +12,13 @@ public T Value
1212
throw new InvalidOperationException($"Attempted to get {typeof(T).Name} before it was set.");
1313
return field;
1414
}
15-
set
15+
init
1616
{
1717
field = value;
1818
_set = true;
1919
}
2020
}
2121

2222
public static implicit operator T(MustSet<T> wrapper) => wrapper.Value;
23-
public static implicit operator MustSet<T>(T value) => new MustSet<T> { Value = value };
23+
public static implicit operator MustSet<T>(T value) => new() { Value = value };
2424
}

Helpers/ResultSystem/DynamicTryGet.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,7 @@ namespace SER.Helpers.ResultSystem;
44

55
public abstract class DynamicTryGet
66
{
7-
private readonly bool _isStaticSet = false;
8-
public bool IsStatic
9-
{
10-
get
11-
{
12-
if (!_isStaticSet) throw new AndrzejFuckedUpException("IsStatic cannot be accessed before it is set.");
13-
return field;
14-
}
15-
protected init
16-
{
17-
_isStaticSet = true;
18-
field = value;
19-
}
20-
}
7+
public MustSet<bool> IsStatic { get; protected init; }
218

229
public abstract Result Result { get; }
2310

0 commit comments

Comments
 (0)