Skip to content

Adds setting to configure leaving stream open #605

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

Merged
merged 6 commits into from
Jun 14, 2021

Conversation

irvinesunday
Copy link
Contributor

Fixes #530
Closes microsoftgraph/microsoft-graph-devx-api#583

This PR:

  • Adds a new boolean setting in OpenApiReaderSettings.cs: LeaveStreamOpen to flag whether or not to leave the stream object open after reading from an OpenApiStreamReader object.
    Creating a StreamReader object within a using statement closes the stream when the Dispose() method of the StreamReader is called.
  • Creates OpenApiStreamReader tests to validate setting the LeaveStreamOpen setting to either true or false.

@irvinesunday irvinesunday self-assigned this Jun 7, 2021
public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
{
using (var reader = new StreamReader(input))
if (_settings.LeaveStreamOpen)
Copy link
Member

Choose a reason for hiding this comment

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

var reader = new StreamReader(input);
var result = new OpenApiTextReaderReader(_settings).Read(reader, out diagnostic);
if (!_settings.LeaveStreamOpen)
   reader.Dispose();
return result;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Much cleaner!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like brackets after if statements though, even for one-liners 😄

Copy link
Member

Choose a reason for hiding this comment

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

I won't fight coding preferences. It seems that I'm the only one on the team to like one liners with no brackets 😅

irvinesunday and others added 3 commits June 7, 2021 15:42
- Remove default assignment of false boolean to setting
- Code simplification
…ble' into is/OpenApiStreamReader-configurable
@irvinesunday irvinesunday merged commit 6bb23b6 into vnext Jun 14, 2021
@irvinesunday irvinesunday deleted the is/OpenApiStreamReader-configurable branch June 14, 2021 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants