From 98221a399da9667232030552957736abde82298a Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Tue, 4 Jul 2023 15:54:23 -0400 Subject: [PATCH] Revert "Refactor duplicate JSON reader creation code" This reverts commit 8ce7dcadf23c51bf53c93416bc37b54acd3bf7ad. --- ...orkloadManifestProvider.GlobalJsonReader.cs | 17 +++++++++++++++-- ...kloadManifestProvider.InstallStateReader.cs | 15 ++++++++++++++- ...ctoryWorkloadManifestProvider.JsonReader.cs | 18 ------------------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.cs b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.cs index 7cf79facd6f3..df0035afedca 100644 --- a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.cs +++ b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.GlobalJsonReader.cs @@ -23,7 +23,7 @@ public partial class SdkDirectoryWorkloadManifestProvider { static class GlobalJsonReader { - public static string? GetWorkloadVersionFromGlobalJson(string? globalJsonPath) + public static string? GetWorkloadVersionFromGlobalJson(string globalJsonPath) { if (string.IsNullOrEmpty(globalJsonPath)) { @@ -31,7 +31,20 @@ static class GlobalJsonReader } 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; diff --git a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.InstallStateReader.cs b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.InstallStateReader.cs index 32e47f7df400..903f420b7a2b 100644 --- a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.InstallStateReader.cs +++ b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.InstallStateReader.cs @@ -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(); diff --git a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.JsonReader.cs b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.JsonReader.cs index cd720f834da4..6045ad1e653c 100644 --- a/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.JsonReader.cs +++ b/src/Resolvers/Microsoft.NET.Sdk.WorkloadManifestReader/SdkDirectoryWorkloadManifestProvider.JsonReader.cs @@ -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; - } - /// /// this expects the reader to be before the value token, and leaves it on the last token of the value ///