diff --git a/src/Microsoft.OpenApi/Reader/ReadResult.cs b/src/Microsoft.OpenApi/Reader/ReadResult.cs index a0013b249..aa835478a 100644 --- a/src/Microsoft.OpenApi/Reader/ReadResult.cs +++ b/src/Microsoft.OpenApi/Reader/ReadResult.cs @@ -18,5 +18,13 @@ public class ReadResult /// OpenApiDiagnostic contains the Errors reported while parsing /// public OpenApiDiagnostic Diagnostic { get; set; } + /// + /// Deconstructs the result for easier assignment on the client application. + /// + public void Deconstruct(out OpenApiDocument document, out OpenApiDiagnostic diagnostic) + { + document = Document; + diagnostic = Diagnostic; + } } } diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index a3681e9d5..642dd0b82 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -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 { diff --git a/test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs b/test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs new file mode 100644 index 000000000..c3a87c7a3 --- /dev/null +++ b/test/Microsoft.OpenApi.Tests/Reader/ReadResultTests.cs @@ -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); + } +}