Skip to content

Commit 1d7b822

Browse files
committed
不用少珺的库设计有坑
1 parent 6c7466b commit 1d7b822

3 files changed

Lines changed: 27 additions & 32 deletions

File tree

Code/UsingMSBuildCopyOutputFileToFastDebug/LaunchSettingsParser.cs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using System.Xml;
1010
using Lsj.Util.Collections;
1111
using Lsj.Util.JSON;
12+
using Newtonsoft.Json;
13+
using Newtonsoft.Json.Linq;
1214

1315
namespace UsingMSBuildCopyOutputFileToFastDebug
1416
{
@@ -27,27 +29,19 @@ public bool Execute()
2729

2830
var text = File.ReadAllText(file);
2931

30-
var o = JSONParser.Parse(text);
31-
var profiles = o.profiles;
32-
var data = profiles.data;
33-
if (data is SafeDictionary<string, object> d)
32+
var root = (JObject) JsonConvert.DeserializeObject(text);
33+
var profilesObject = (JObject)root["profiles"];
34+
35+
foreach (var keyValuePair in profilesObject)
3436
{
35-
foreach (var keyValuePair in d)
37+
var commandName = keyValuePair.Value["commandName"];
38+
if (commandName?.ToString() == "Executable")
3639
{
37-
if (keyValuePair.Value is JSONObject jsonObject)
40+
var executablePath = keyValuePair.Value["executablePath"];
41+
if (executablePath != null)
3842
{
39-
if (jsonObject.TryGetMember(new CustomGetMemberBinder("ExecutablePath", true),
40-
out var filePath))
41-
{
42-
var path = filePath?.ToString();
43-
44-
if (!string.IsNullOrEmpty(path))
45-
{
46-
LaunchMainProjectPath = Path.GetDirectoryName(path);
47-
Console.WriteLine($"读取到 {LaunchMainProjectPath} 文件夹");
48-
return true;
49-
}
50-
}
43+
LaunchMainProjectPath = executablePath.ToString();
44+
return true;
5145
}
5246
}
5347
}
@@ -57,18 +51,4 @@ public bool Execute()
5751

5852
public string LaunchMainProjectPath { set; get; }
5953
}
60-
61-
public class CustomGetMemberBinder : GetMemberBinder
62-
{
63-
/// <inheritdoc />
64-
public CustomGetMemberBinder(string name, bool ignoreCase) : base(name, ignoreCase)
65-
{
66-
}
67-
68-
/// <inheritdoc />
69-
public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
70-
{
71-
return null;
72-
}
73-
}
7454
}

Code/UsingMSBuildCopyOutputFileToFastDebug/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using dotnetCampus.Cli;
@@ -52,7 +53,20 @@ static int Main(string[] args)
5253

5354
private static void CopyOutputFile(CopyOutputFileOptions copyOutputFileOptions)
5455
{
56+
var targetFolder = GetTargetFolder(copyOutputFileOptions);
57+
var outputFileList = GetOutputFileList(copyOutputFileOptions.OutputFileToCopyList);
58+
}
59+
60+
private static List<FileInfo> GetOutputFileList(string outputFileToCopyList)
61+
{
62+
var fileList = new List<FileInfo>();
63+
foreach (var file in outputFileToCopyList.Split(System.IO.Path.PathSeparator))
64+
{
65+
// 不要优化 Linq 我需要调试这些文件,在这里加断点
66+
fileList.Add(new FileInfo(file));
67+
}
5568

69+
return fileList;
5670
}
5771

5872
/// <summary>

Code/UsingMSBuildCopyOutputFileToFastDebug/UsingMSBuildCopyOutputFileToFastDebug.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
1717
<PackageReference Include="Lsj.Util.JSON" Version="5.1.1" />
18+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1819
</ItemGroup>
1920
</Project>

0 commit comments

Comments
 (0)