Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds deconstructor to read result #2024

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much magic in the C# language these days!!!

{
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);
}
}
Loading