diff --git a/.editorconfig b/.editorconfig index 887ee1e..def8856 100644 --- a/.editorconfig +++ b/.editorconfig @@ -140,8 +140,8 @@ csharp_style_pattern_local_over_anonymous_function = true:suggestion csharp_style_prefer_index_operator = true:suggestion csharp_style_prefer_range_operator = true:suggestion csharp_style_throw_expression = true:suggestion -csharp_style_unused_value_assignment_preference = discard_variable:suggestion -csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:none +csharp_style_unused_value_expression_statement_preference = discard_variable:none # 'using' directive preferences csharp_using_directive_placement = outside_namespace:suggestion diff --git a/OperationResults.sln b/OperationResults.sln index 08d384c..4a6a339 100644 --- a/OperationResults.sln +++ b/OperationResults.sln @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig src\Directory.Build.props = src\Directory.Build.props + README.md = README.md EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{40EA0531-BCD9-4D33-9114-D1BB9EA7DDBA}" diff --git a/samples/OperationResults.Sample.BusinessLayer/Services/PeopleService.cs b/samples/OperationResults.Sample.BusinessLayer/Services/PeopleService.cs index 8915bcb..ddd81d1 100644 --- a/samples/OperationResults.Sample.BusinessLayer/Services/PeopleService.cs +++ b/samples/OperationResults.Sample.BusinessLayer/Services/PeopleService.cs @@ -48,15 +48,16 @@ public async Task> GetAsync(Guid id) public async Task> GetWithImageAsync(Guid id) { var personResult = await GetAsync(id); + if (!personResult) // A shortcut to !personResult.Success { - // The person operation failed return Result.Fail(personResult.FailureReason); } var person = personResult.Content!; + var imageResult = await imageService.GetImageAsync(); - if (imageResult.TryGet(out var imageFileContent) && imageFileContent is not null) + if (imageResult.TryGetContent(out var imageFileContent) && imageFileContent is not null) { // The image operation succeeded, return person with image var personWithImage = new PersonWithImage diff --git a/samples/OperationResults.Sample.Shared/Models/PersonWithImage.cs b/samples/OperationResults.Sample.Shared/Models/PersonWithImage.cs index 21ee318..1c8f996 100644 --- a/samples/OperationResults.Sample.Shared/Models/PersonWithImage.cs +++ b/samples/OperationResults.Sample.Shared/Models/PersonWithImage.cs @@ -3,5 +3,6 @@ namespace OperationResults.Sample.Shared.Models; public class PersonWithImage { public Person Person { get; set; } + public byte[] Image { get; set; } } \ No newline at end of file diff --git a/src/OperationResults.AspNetCore.Http/OperationResults.AspNetCore.Http.csproj b/src/OperationResults.AspNetCore.Http/OperationResults.AspNetCore.Http.csproj index c204813..f9a4644 100644 --- a/src/OperationResults.AspNetCore.Http/OperationResults.AspNetCore.Http.csproj +++ b/src/OperationResults.AspNetCore.Http/OperationResults.AspNetCore.Http.csproj @@ -33,6 +33,5 @@ True - diff --git a/src/OperationResults.AspNetCore/OperationResults.AspNetCore.csproj b/src/OperationResults.AspNetCore/OperationResults.AspNetCore.csproj index b895b64..fae7ed8 100644 --- a/src/OperationResults.AspNetCore/OperationResults.AspNetCore.csproj +++ b/src/OperationResults.AspNetCore/OperationResults.AspNetCore.csproj @@ -33,6 +33,5 @@ True - diff --git a/src/OperationResults/IGenericResult{OfT}.cs b/src/OperationResults/IGenericResult{OfT}.cs index af0dfc7..ecf7d3f 100644 --- a/src/OperationResults/IGenericResult{OfT}.cs +++ b/src/OperationResults/IGenericResult{OfT}.cs @@ -1,8 +1,10 @@ +using System.Diagnostics.CodeAnalysis; + namespace OperationResults; public interface IGenericResult : IGenericResult { public T? Content { get; } - public bool TryGet(out T? value); + public bool TryGetContent([NotNullWhen(returnValue: true)] T? content); } diff --git a/src/OperationResults/OperationResults.csproj b/src/OperationResults/OperationResults.csproj index 2319be2..624db12 100644 --- a/src/OperationResults/OperationResults.csproj +++ b/src/OperationResults/OperationResults.csproj @@ -26,7 +26,6 @@ True - diff --git a/src/OperationResults/Result{OfT}.cs b/src/OperationResults/Result{OfT}.cs index f8df882..78732e7 100644 --- a/src/OperationResults/Result{OfT}.cs +++ b/src/OperationResults/Result{OfT}.cs @@ -1,3 +1,5 @@ +using System.Diagnostics.CodeAnalysis; + namespace OperationResults; public class Result : IGenericResult @@ -29,9 +31,9 @@ internal Result(bool success = true, T? content = default, int failureReason = F ValidationErrors = validationErrors; } - public bool TryGet(out T? value) + public bool TryGetContent([NotNullWhen(returnValue: true)] T? content) { - value = Content; + content = Content; return Success; }