Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 756f905

Browse files
committed
React to System.Text.Json changes
1 parent eff71e6 commit 756f905

File tree

8 files changed

+40
-40
lines changed

8 files changed

+40
-40
lines changed

src/dotnet/ToolManifest/JsonElementExtension.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ internal static bool TryGetStringValue(this JsonElement element, string name, ou
1515
value = null;
1616
if (element.TryGetProperty(name, out JsonElement jsonValue))
1717
{
18-
if (jsonValue.Type != JsonValueType.String)
18+
if (jsonValue.ValueKind != JsonValueKind.String)
1919
{
2020
throw new ToolManifestException(
2121
string.Format(
2222
LocalizableStrings.UnexpectedTypeInJson,
23-
JsonValueType.String.ToString(),
23+
JsonValueKind.String.ToString(),
2424
name));
2525
}
2626
value = jsonValue.GetString();
@@ -35,12 +35,12 @@ internal static bool TryGetInt32Value(this JsonElement element, string name, out
3535
value = default;
3636
if (element.TryGetProperty(name, out JsonElement jsonValue))
3737
{
38-
if (jsonValue.Type != JsonValueType.Number)
38+
if (jsonValue.ValueKind != JsonValueKind.Number)
3939
{
4040
throw new ToolManifestException(
4141
string.Format(
4242
LocalizableStrings.UnexpectedTypeInJson,
43-
JsonValueType.Number.ToString(),
43+
JsonValueKind.Number.ToString(),
4444
name));
4545
}
4646
value = jsonValue.GetInt32();
@@ -55,12 +55,12 @@ internal static bool TryGetBooleanValue(this JsonElement element, string name, o
5555
value = default;
5656
if (element.TryGetProperty(name, out JsonElement jsonValue))
5757
{
58-
if (!(jsonValue.Type == JsonValueType.True || jsonValue.Type == JsonValueType.False))
58+
if (!(jsonValue.ValueKind == JsonValueKind.True || jsonValue.ValueKind == JsonValueKind.False))
5959
{
6060
throw new ToolManifestException(
6161
string.Format(
6262
LocalizableStrings.UnexpectedTypeInJson,
63-
JsonValueType.True.ToString() + "|" + JsonValueType.False.ToString(),
63+
JsonValueKind.True.ToString() + "|" + JsonValueKind.False.ToString(),
6464
name));
6565
}
6666
value = jsonValue.GetBoolean();

src/dotnet/ToolManifest/ToolManifestEditor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ private SerializableLocalToolsManifest DeserializeLocalToolsManifest(FilePath po
164164
serializableLocalToolsManifest.Tools =
165165
new List<SerializableLocalToolSinglePackage>();
166166

167-
if (tools.Type != JsonValueType.Object)
167+
if (tools.ValueKind != JsonValueKind.Object)
168168
{
169169
throw new ToolManifestException(
170170
string.Format(LocalizableStrings.UnexpectedTypeInJson,
171-
JsonValueType.Object.ToString(),
171+
JsonValueKind.Object.ToString(),
172172
JsonPropertyTools));
173173
}
174174

@@ -184,21 +184,21 @@ private SerializableLocalToolsManifest DeserializeLocalToolsManifest(FilePath po
184184
var commands = new List<string>();
185185
if (toolJson.Value.TryGetProperty(JsonPropertyCommands, out var commandsJson))
186186
{
187-
if (commandsJson.Type != JsonValueType.Array)
187+
if (commandsJson.ValueKind != JsonValueKind.Array)
188188
{
189189
throw new ToolManifestException(
190190
string.Format(LocalizableStrings.UnexpectedTypeInJson,
191-
JsonValueType.Array.ToString(),
191+
JsonValueKind.Array.ToString(),
192192
JsonPropertyCommands));
193193
}
194194

195195
foreach (var command in commandsJson.EnumerateArray())
196196
{
197-
if (command.Type != JsonValueType.String)
197+
if (command.ValueKind != JsonValueKind.String)
198198
{
199199
throw new ToolManifestException(
200200
string.Format(LocalizableStrings.UnexpectedTypeInJson,
201-
JsonValueType.String.ToString(),
201+
JsonValueKind.String.ToString(),
202202
"command"));
203203
}
204204

src/dotnet/ToolPackage/LocalToolsResolverCache.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void Save(
5151

5252
_fileSystem.File.WriteAllText(
5353
packageCacheFile,
54-
JsonSerializer.ToString(existingCacheTable.Concat(diffedRow)));
54+
JsonSerializer.Serialize(existingCacheTable.Concat(diffedRow)));
5555
}
5656
else
5757
{
@@ -64,7 +64,7 @@ public void Save(
6464

6565
_fileSystem.File.WriteAllText(
6666
packageCacheFile,
67-
JsonSerializer.ToString(rowsToAdd));
67+
JsonSerializer.Serialize(rowsToAdd));
6868
}
6969
}
7070
}
@@ -96,7 +96,7 @@ private CacheRow[] GetCacheTable(string packageCacheFile)
9696
try
9797
{
9898
cacheTable =
99-
JsonSerializer.Parse<CacheRow[]>(_fileSystem.File.ReadAllText(packageCacheFile));
99+
JsonSerializer.Deserialize<CacheRow[]>(_fileSystem.File.ReadAllText(packageCacheFile));
100100
}
101101
catch (JsonException)
102102
{

src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett
2929
{
3030
var model = document.RootElement;
3131

32-
if (model.Type != JsonValueType.Object || !model.TryGetProperty(ProfilesKey, out var profilesObject) || profilesObject.Type != JsonValueType.Object)
32+
if (model.ValueKind != JsonValueKind.Object || !model.TryGetProperty(ProfilesKey, out var profilesObject) || profilesObject.ValueKind != JsonValueKind.Object)
3333
{
3434
return new LaunchSettingsApplyResult(false, LocalizableStrings.LaunchProfilesCollectionIsNotAJsonObject);
3535
}
@@ -43,19 +43,19 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett
4343
}
4444
else
4545
{
46-
if (!profilesObject.TryGetProperty(profileName, out profileObject) || profileObject.Type != JsonValueType.Object)
46+
if (!profilesObject.TryGetProperty(profileName, out profileObject) || profileObject.ValueKind != JsonValueKind.Object)
4747
{
4848
return new LaunchSettingsApplyResult(false, LocalizableStrings.LaunchProfileIsNotAJsonObject);
4949
}
5050
}
5151

52-
if (profileObject.Type == default)
52+
if (profileObject.ValueKind == default)
5353
{
5454
foreach (var prop in profilesObject.EnumerateObject())
5555
{
56-
if (prop.Value.Type == JsonValueType.Object)
56+
if (prop.Value.ValueKind == JsonValueKind.Object)
5757
{
58-
if (prop.Value.TryGetProperty(CommandNameKey, out var commandNameElement) && commandNameElement.Type == JsonValueType.String)
58+
if (prop.Value.TryGetProperty(CommandNameKey, out var commandNameElement) && commandNameElement.ValueKind == JsonValueKind.String)
5959
{
6060
if (_providers.ContainsKey(commandNameElement.GetString()))
6161
{
@@ -67,13 +67,13 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett
6767
}
6868
}
6969

70-
if (profileObject.Type == default)
70+
if (profileObject.ValueKind == default)
7171
{
7272
return new LaunchSettingsApplyResult(false, LocalizableStrings.UsableLaunchProfileCannotBeLocated);
7373
}
7474

7575
if (!profileObject.TryGetProperty(CommandNameKey, out var finalCommandNameElement)
76-
|| finalCommandNameElement.Type != JsonValueType.String)
76+
|| finalCommandNameElement.ValueKind != JsonValueKind.String)
7777
{
7878
return new LaunchSettingsApplyResult(false, LocalizableStrings.UsableLaunchProfileCannotBeLocated);
7979
}
@@ -100,9 +100,9 @@ private static bool TryLocateHandler(string commandName, out ILaunchSettingsProv
100100

101101
private static bool IsDefaultProfileType(JsonProperty profileProperty)
102102
{
103-
if (profileProperty.Value.Type != JsonValueType.Object
103+
if (profileProperty.Value.ValueKind != JsonValueKind.Object
104104
|| !profileProperty.Value.TryGetProperty(CommandNameKey, out var commandNameElement)
105-
|| commandNameElement.Type != JsonValueType.String)
105+
|| commandNameElement.ValueKind != JsonValueKind.String)
106106
{
107107
return false;
108108
}

src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref IComman
5454
}
5555
else if (string.Equals(property.Name, nameof(ProjectLaunchSettingsModel.EnvironmentVariables), StringComparison.OrdinalIgnoreCase))
5656
{
57-
if (property.Value.Type != JsonValueType.Object)
57+
if (property.Value.ValueKind != JsonValueKind.Object)
5858
{
5959
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.ValueMustBeAnObject, property.Name));
6060
}
@@ -88,23 +88,23 @@ public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref IComman
8888

8989
private static bool TryGetBooleanValue(JsonElement element, out bool value)
9090
{
91-
switch (element.Type)
91+
switch (element.ValueKind)
9292
{
93-
case JsonValueType.True:
93+
case JsonValueKind.True:
9494
value = true;
9595
return true;
96-
case JsonValueType.False:
96+
case JsonValueKind.False:
9797
value = false;
9898
return true;
99-
case JsonValueType.Number:
99+
case JsonValueKind.Number:
100100
if (element.TryGetDouble(out var doubleValue))
101101
{
102102
value = doubleValue != 0;
103103
return true;
104104
}
105105
value = false;
106106
return false;
107-
case JsonValueType.String:
107+
case JsonValueKind.String:
108108
return bool.TryParse(element.GetString(), out value);
109109
default:
110110
value = false;
@@ -114,21 +114,21 @@ private static bool TryGetBooleanValue(JsonElement element, out bool value)
114114

115115
private static bool TryGetStringValue(JsonElement element, out string value)
116116
{
117-
switch (element.Type)
117+
switch (element.ValueKind)
118118
{
119-
case JsonValueType.True:
119+
case JsonValueKind.True:
120120
value = bool.TrueString;
121121
return true;
122-
case JsonValueType.False:
122+
case JsonValueKind.False:
123123
value = bool.FalseString;
124124
return true;
125-
case JsonValueType.Null:
125+
case JsonValueKind.Null:
126126
value = string.Empty;
127127
return true;
128-
case JsonValueType.Number:
128+
case JsonValueKind.Number:
129129
value = element.GetRawText();
130130
return false;
131-
case JsonValueType.String:
131+
case JsonValueKind.String:
132132
value = element.GetString();
133133
return true;
134134
default:

test/Microsoft.DotNet.Tools.Tests.ComponentMocks/AppHostShellShimMakerMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void CreateApphostShellShim(FilePath entryPoint, FilePath shimPath)
2626

2727
_fileSystem.File.WriteAllText(
2828
shimPath.Value,
29-
JsonSerializer.ToString(shim));
29+
JsonSerializer.Serialize(shim));
3030
}
3131

3232
public class FakeShim

test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ProjectRestorerMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void Restore(FilePath project,
114114
fakeExecutablePath);
115115
_fileSystem.File.WriteAllText(
116116
assetJsonOutput.WithFile(FakeCommandSettingsFileName).Value,
117-
JsonSerializer.ToString(new {Name = feedPackage.ToolCommandName}));
117+
JsonSerializer.Serialize(new {Name = feedPackage.ToolCommandName}));
118118
}
119119

120120
public MockFeedPackage GetPackage(

test/dotnet.Tests/CommandTests/ToolInstallGlobalOrToolPathCommandTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void WhenRunWithPackageIdItShouldCreateValidShim()
8484

8585
// It is hard to simulate shell behavior. Only Assert shim can point to executable dll
8686
_fileSystem.File.Exists(ExpectedCommandPath()).Should().BeTrue();
87-
var deserializedFakeShim = JsonSerializer.Parse<AppHostShellShimMakerMock.FakeShim>(
87+
var deserializedFakeShim = JsonSerializer.Deserialize<AppHostShellShimMakerMock.FakeShim>(
8888
_fileSystem.File.ReadAllText(ExpectedCommandPath()));
8989

9090
_fileSystem.File.Exists(deserializedFakeShim.ExecutablePath).Should().BeTrue();
@@ -151,7 +151,7 @@ public void WhenRunWithPackageIdWithSourceItShouldCreateValidShim()
151151
_fileSystem.File.Exists(ExpectedCommandPath())
152152
.Should().BeTrue();
153153
var deserializedFakeShim =
154-
JsonSerializer.Parse<AppHostShellShimMakerMock.FakeShim>(
154+
JsonSerializer.Deserialize<AppHostShellShimMakerMock.FakeShim>(
155155
_fileSystem.File.ReadAllText(ExpectedCommandPath()));
156156
_fileSystem.File.Exists(deserializedFakeShim.ExecutablePath).Should().BeTrue();
157157
}

0 commit comments

Comments
 (0)