Skip to content

Commit d523bc0

Browse files
committed
refactor(results): update Result class for nullable types
- Adjusts the Result class to enforce non-nullable constraints on generic types. - Simplifies the results tests by directly checking for null instead of multiple assertions. - Updates method signatures for better type safety and clarity.
1 parent 81dd1bf commit d523bc0

2 files changed

Lines changed: 3 additions & 13 deletions

File tree

src/ES.FX/Results/Result.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Result(Problem problem) : base(problem)
3434
/// </summary>
3535
/// <typeparam name="T">Type of result</typeparam>
3636
[PublicAPI]
37-
public class Result<T> : IResult
37+
public class Result<T> : IResult where T : notnull
3838
{
3939
private readonly Problem? _problem;
4040
private readonly T? _result;

tests/ES.FX.Tests/Results/ResultsTests.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,7 @@ public class ResultsTests
1010
public void TypedResult_CanBe_Null()
1111
{
1212
var result = TypedResultAsNull();
13-
Assert.True(result.IsResult);
14-
15-
if(result.TryPickResult(out var resultValue))
16-
{
17-
Assert.Null(resultValue);
18-
}
19-
20-
if (!result.TryPickProblem(out var problemValue))
21-
{
22-
Assert.Null(problemValue);
23-
}
13+
Assert.Null(result);
2414
}
2515

2616
[Fact]
@@ -121,7 +111,7 @@ public void Results_CanBeEqualityChecked()
121111

122112
private static Result<string> TypedResultAsProblem() => new Problem();
123113
private static Result<string> TypedResultAsValue() => string.Empty;
124-
private static Result<object?> TypedResultAsNull() => (object?)null;
114+
private static Result<object>? TypedResultAsNull() => null;
125115

126116

127117
}

0 commit comments

Comments
 (0)