Skip to content

Commit

Permalink
Revert "Refactor duplicate JSON reader creation code"
Browse files Browse the repository at this point in the history
This reverts commit 8ce7dca.
  • Loading branch information
dsplaisted committed Jul 4, 2023
1 parent a561d2f commit 98221a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,28 @@ public partial class SdkDirectoryWorkloadManifestProvider
{
static class GlobalJsonReader
{
public static string? GetWorkloadVersionFromGlobalJson(string? globalJsonPath)
public static string? GetWorkloadVersionFromGlobalJson(string globalJsonPath)
{
if (string.IsNullOrEmpty(globalJsonPath))
{
return null;
}

using var fileStream = File.OpenRead(globalJsonPath);
var reader = JsonReader.CreateReader(fileStream);

#if USE_SYSTEM_TEXT_JSON
var readerOptions = new JsonReaderOptions
{
AllowTrailingCommas = true,
CommentHandling = JsonCommentHandling.Skip
};
var reader = new Utf8JsonStreamReader(fileStream, readerOptions);
#else
using var textReader = new StreamReader(fileStream, System.Text.Encoding.UTF8, true);
using var jsonReader = new JsonTextReader(textReader);

var reader = new Utf8JsonStreamReader(jsonReader);
#endif

string? workloadVersion = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ static class InstallStateReader
public static InstallState ReadInstallState(string installStatePath)
{
using var fileStream = File.OpenRead(installStatePath);
var reader = JsonReader.CreateReader(fileStream);

#if USE_SYSTEM_TEXT_JSON
var readerOptions = new JsonReaderOptions
{
AllowTrailingCommas = true,
CommentHandling = JsonCommentHandling.Skip
};
var reader = new Utf8JsonStreamReader(fileStream, readerOptions);
#else
using var textReader = new StreamReader(fileStream, System.Text.Encoding.UTF8, true);
using var jsonReader = new JsonTextReader(textReader);

var reader = new Utf8JsonStreamReader(jsonReader);
#endif

InstallState installState = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ public partial class SdkDirectoryWorkloadManifestProvider
static class JsonReader
{

internal static Utf8JsonStreamReader CreateReader(FileStream fileStream)
{
#if USE_SYSTEM_TEXT_JSON
var readerOptions = new JsonReaderOptions
{
AllowTrailingCommas = true,
CommentHandling = JsonCommentHandling.Skip
};
var reader = new Utf8JsonStreamReader(fileStream, readerOptions);
#else
using var textReader = new StreamReader(fileStream, System.Text.Encoding.UTF8, true);
using var jsonReader = new JsonTextReader(textReader);

var reader = new Utf8JsonStreamReader(jsonReader);
#endif
return reader;
}

/// <summary>
/// this expects the reader to be before the value token, and leaves it on the last token of the value
/// </summary>
Expand Down

0 comments on commit 98221a3

Please sign in to comment.