Skip to content

Commit

Permalink
Merge pull request #2024 from microsoft/feat/result-deconstruct
Browse files Browse the repository at this point in the history
feat: adds deconstructor to read result
  • Loading branch information
baywet authored Dec 24, 2024
2 parents ff7b4a9 + 8902656 commit 79336f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Microsoft.OpenApi/Reader/ReadResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ public class ReadResult
/// OpenApiDiagnostic contains the Errors reported while parsing
/// </summary>
public OpenApiDiagnostic Diagnostic { get; set; }
/// <summary>
/// Deconstructs the result for easier assignment on the client application.
/// </summary>
public void Deconstruct(out OpenApiDocument document, out OpenApiDiagnostic diagnostic)
{
document = Document;
diagnostic = Diagnostic;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,7 @@ namespace Microsoft.OpenApi.Reader
public ReadResult() { }
public Microsoft.OpenApi.Reader.OpenApiDiagnostic Diagnostic { get; set; }
public Microsoft.OpenApi.Models.OpenApiDocument Document { get; set; }
public void Deconstruct(out Microsoft.OpenApi.Models.OpenApiDocument document, out Microsoft.OpenApi.Reader.OpenApiDiagnostic diagnostic) { }
}
public enum ReferenceResolutionSetting
{
Expand Down
21 changes: 21 additions & 0 deletions test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Xunit;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Models;

namespace Microsoft.OpenApi.Tests.Reader;

public class ReadResultTests
{
[Fact]
public void Deconstructs()
{
var readResult = new ReadResult()
{
Document = new OpenApiDocument(),
Diagnostic = new OpenApiDiagnostic()
};
var (document, diagnostic) = readResult;
Assert.Equal(readResult.Document, document);
Assert.Equal(readResult.Diagnostic, diagnostic);
}
}

0 comments on commit 79336f6

Please sign in to comment.