|
5 | 5 | using System.Collections.Generic;
|
6 | 6 | using System.IO;
|
7 | 7 | using System.Linq;
|
| 8 | +using System.Text.Json; |
8 | 9 | using Coverlet.Core.Abstractions;
|
9 | 10 | using Coverlet.Core.Exceptions;
|
10 | 11 | using Microsoft.Extensions.DependencyModel;
|
11 | 12 | using Microsoft.Extensions.DependencyModel.Resolution;
|
12 | 13 | using Mono.Cecil;
|
13 |
| -using Newtonsoft.Json.Linq; |
14 | 14 | using NuGet.Versioning;
|
15 | 15 |
|
16 | 16 | namespace Coverlet.Core.Instrumentation
|
@@ -298,29 +298,29 @@ public RuntimeConfigurationReader(string runtimeConfigFile)
|
298 | 298 | {
|
299 | 299 | string jsonString = File.ReadAllText(_runtimeConfigFile);
|
300 | 300 |
|
301 |
| - var jsonLoadSettings = new JsonLoadSettings() |
| 301 | + var documentOptions = new JsonDocumentOptions |
302 | 302 | {
|
303 |
| - CommentHandling = CommentHandling.Ignore |
| 303 | + CommentHandling = JsonCommentHandling.Skip |
304 | 304 | };
|
305 | 305 |
|
306 |
| - var configuration = JObject.Parse(jsonString, jsonLoadSettings); |
| 306 | + using var configuration = JsonDocument.Parse(jsonString, documentOptions); |
307 | 307 |
|
308 |
| - JToken rootElement = configuration.Root; |
309 |
| - JToken runtimeOptionsElement = rootElement["runtimeOptions"]; |
| 308 | + JsonElement rootElement = configuration.RootElement; |
| 309 | + JsonElement runtimeOptionsElement = rootElement.GetProperty("runtimeOptions"); |
310 | 310 |
|
311 |
| - if (runtimeOptionsElement?["framework"] != null) |
| 311 | + if (runtimeOptionsElement.TryGetProperty("framework", out JsonElement frameworkElement)) |
312 | 312 | {
|
313 |
| - return new[] { (runtimeOptionsElement["framework"]["name"]?.Value<string>(), runtimeOptionsElement["framework"]["version"]?.Value<string>()) }; |
| 313 | + return new[] { (frameworkElement.GetProperty("name").GetString(), frameworkElement.GetProperty("version").GetString()) }; |
314 | 314 | }
|
315 | 315 |
|
316 |
| - if (runtimeOptionsElement?["frameworks"] != null) |
| 316 | + if (runtimeOptionsElement.TryGetProperty("frameworks", out JsonElement frameworksElement)) |
317 | 317 | {
|
318 |
| - return runtimeOptionsElement["frameworks"].Select(x => (x["name"]?.Value<string>(), x["version"]?.Value<string>())).ToList(); |
| 318 | + return frameworksElement.EnumerateArray().Select(x => (x.GetProperty("name").GetString(), x.GetProperty("version").GetString())).ToList(); |
319 | 319 | }
|
320 | 320 |
|
321 |
| - if (runtimeOptionsElement?["includedFrameworks"] != null) |
| 321 | + if (runtimeOptionsElement.TryGetProperty("includedframeworks", out JsonElement runtimeoptionselement)) |
322 | 322 | {
|
323 |
| - return runtimeOptionsElement["includedFrameworks"].Select(x => (x["name"]?.Value<string>(), x["version"]?.Value<string>())).ToList(); |
| 323 | + return runtimeoptionselement.EnumerateArray().Select(x => (x.GetProperty("name").GetString(), x.GetProperty("version").GetString())).ToList(); |
324 | 324 | }
|
325 | 325 |
|
326 | 326 | throw new InvalidOperationException($"Unable to read runtime configuration from {_runtimeConfigFile}.");
|
|
0 commit comments