Skip to content

Commit e2ff464

Browse files
committed
refine GetAssembliesByProductName
1 parent 44afe44 commit e2ff464

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

最后大项目代码/YouZack-VNext/Zack.Commons/ReflectionHelper.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,24 @@
1111
namespace Zack.Commons;
1212
public static class ReflectionHelper
1313
{
14-
//增加一个根据产品名称获取assembly的方法GetAssembliesByProductName
15-
public static List<Assembly>? GetAssembliesByProductName(string ProductName)
16-
{
17-
var asms = new List<Assembly>();
18-
var assm = AppDomain.CurrentDomain.GetAssemblies();
19-
foreach (var assa in assm)
20-
{
2114

22-
var asmCompanyAtt = assa.GetCustomAttribute<AssemblyProductAttribute>();
23-
if (asmCompanyAtt != null)
24-
{
25-
if (asmCompanyAtt.Product == ProductName) {
26-
asms.Add(assa);
27-
}
28-
}
29-
30-
}
31-
32-
return asms;
33-
}
15+
/// <summary>
16+
/// 据产品名称获取程序集
17+
/// </summary>
18+
/// <param name="productName"></param>
19+
/// <returns></returns>
20+
public static IEnumerable<Assembly> GetAssembliesByProductName(string productName)
21+
{
22+
var asms = AppDomain.CurrentDomain.GetAssemblies();
23+
foreach (var asm in asms)
24+
{
25+
var asmCompanyAttr = asm.GetCustomAttribute<AssemblyProductAttribute>();
26+
if (asmCompanyAttr != null&& asmCompanyAttr.Product == productName)
27+
{
28+
yield return asm;
29+
}
30+
}
31+
}
3432
//是否是微软等的官方Assembly
3533
private static bool IsSystemAssembly(Assembly asm)
3634
{

最后大项目代码/YouZack-VNext/Zack.Commons/Zack.Commons.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Authors>Zack Yang</Authors>
88
<PackageProjectUrl>https://github.com/yangzhongke/NETBookMaterials</PackageProjectUrl>
99
<RepositoryUrl>https://github.com/yangzhongke/NETBookMaterials</RepositoryUrl>
10-
<Version>1.1.10</Version>
10+
<Version>1.1.11</Version>
1111
<LangVersion>10.0</LangVersion>
1212
</PropertyGroup>
1313

0 commit comments

Comments
 (0)