Skip to content

Commit 8b80035

Browse files
committed
refactor 1
1 parent a3ad4f2 commit 8b80035

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

Src/Generate/Program.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -333,29 +333,13 @@ public static class ReferenceInfos
333333
""");
334334

335335
var lowerName = name.ToLower();
336-
var dllPaths = new List<string>();
337-
foreach (var realPackagePath in realPackagePaths)
338-
{
339-
dllPaths.AddRange(Directory.GetFiles(realPackagePath, "*.dll"));
340-
var facadesPath = Path.Combine(realPackagePath, "Facades");
341-
if (Directory.Exists(facadesPath))
342-
{
343-
dllPaths.AddRange(Directory.GetFiles(facadesPath, "*.dll"));
344-
}
345-
}
346-
347336
var allPropNames = new List<string>();
348-
foreach (var dllPath in dllPaths)
337+
foreach (var dllInfo in FindDlls(realPackagePaths))
349338
{
350-
var dllName = Path.GetFileName(dllPath)!;
351-
if (GetMvid(dllPath) is not var (mvid, isAssembly) || !isAssembly)
352-
{
353-
continue;
354-
}
355-
339+
var dllName = Path.GetFileName(dllInfo.FilePath)!;
356340
var dll = Path.GetFileNameWithoutExtension(dllName);
357341
var logicalName = $"{lowerName}.{dll}";
358-
var dllResourcePath = Path.Join(targetsPrefix, dllPath.Substring(realPackagePrefix.Length));
342+
var dllResourcePath = Path.Join(targetsPrefix, dllInfo.RelativeFilePath);
359343

360344
targetsContent.AppendLine($$"""
361345
<EmbeddedResource Include="{{dllResourcePath}}" WithCulture="false">
@@ -381,7 +365,7 @@ public static class ReferenceInfos
381365
/// <summary>
382366
/// The <see cref="ReferenceInfo"/> for {{dllName}}
383367
/// </summary>
384-
public static ReferenceInfo {{propName}} => new ReferenceInfo("{{dllName}}", Resources.{{propName}}, {{name}}.References.{{propName}}, global::System.Guid.Parse("{{mvid}}"));
368+
public static ReferenceInfo {{propName}} => new ReferenceInfo("{{dllName}}", Resources.{{propName}}, {{name}}.References.{{propName}}, global::System.Guid.Parse("{{dllInfo.Mvid}}"));
385369
""");
386370

387371
metadataContent.AppendLine($$"""
@@ -487,6 +471,32 @@ namespace Basic.Reference.Assemblies;
487471
""");
488472

489473
return (codeContent.ToString(), targetsContent.ToString());
474+
475+
IEnumerable<(string FilePath, string RelativeFilePath, Guid Mvid)> FindDlls(string[] packagePaths)
476+
{
477+
var dllPaths = new List<string>();
478+
foreach (var realPackagePath in realPackagePaths)
479+
{
480+
dllPaths.AddRange(Directory.GetFiles(realPackagePath, "*.dll"));
481+
var facadesPath = Path.Combine(realPackagePath, "Facades");
482+
if (Directory.Exists(facadesPath))
483+
{
484+
dllPaths.AddRange(Directory.GetFiles(facadesPath, "*.dll"));
485+
}
486+
}
487+
488+
var allPropNames = new List<string>();
489+
foreach (var dllPath in dllPaths)
490+
{
491+
if (GetMvid(dllPath) is not var (mvid, isAssembly) || !isAssembly)
492+
{
493+
continue;
494+
}
495+
496+
var relativeFilePath = dllPath.Substring(realPackagePrefix.Length);
497+
yield return (dllPath, relativeFilePath, mvid);
498+
}
499+
}
490500
}
491501

492502
static (string CodeContent, string TargetsContent) GetGeneratedContent(string name, string[] packagePaths)

0 commit comments

Comments
 (0)