Skip to content

Commit cbd135c

Browse files
committed
优化读取配置的逻辑
1 parent 1d7b822 commit cbd135c

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

Code/UsingMSBuildCopyOutputFileToFastDebug/LaunchSettingsParser.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
using System;
2-
using System.Diagnostics;
3-
using System.Dynamic;
4-
using System.Globalization;
52
using System.IO;
6-
using System.Runtime.Serialization.Json;
7-
using System.Text.Json;
8-
using System.Text.Json.Serialization;
9-
using System.Xml;
10-
using Lsj.Util.Collections;
11-
using Lsj.Util.JSON;
123
using Newtonsoft.Json;
134
using Newtonsoft.Json.Linq;
145

@@ -30,11 +21,21 @@ public bool Execute()
3021
var text = File.ReadAllText(file);
3122

3223
var root = (JObject) JsonConvert.DeserializeObject(text);
24+
if (root == null)
25+
{
26+
return false;
27+
}
28+
3329
var profilesObject = (JObject)root["profiles"];
3430

31+
if (profilesObject == null)
32+
{
33+
return false;
34+
}
35+
3536
foreach (var keyValuePair in profilesObject)
3637
{
37-
var commandName = keyValuePair.Value["commandName"];
38+
var commandName = keyValuePair.Value?["commandName"];
3839
if (commandName?.ToString() == "Executable")
3940
{
4041
var executablePath = keyValuePair.Value["executablePath"];

Code/UsingMSBuildCopyOutputFileToFastDebug/UsingMSBuildCopyOutputFileToFastDebug.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17-
<PackageReference Include="Lsj.Util.JSON" Version="5.1.1" />
1817
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1918
</ItemGroup>
2019
</Project>

0 commit comments

Comments
 (0)