Skip to content

Commit 8fdb5f8

Browse files
committed
允许未继承任何接口的类在导出服务时不显式指定导出服务类型;
1 parent 73b3798 commit 8fdb5f8

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/Cuture.Extensions.Modularity/Attributes/ExportServicesAttribute.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ protected ExportServicesAttribute(byte exportTypes)
116116
/// <inheritdoc/>
117117
public virtual IEnumerable<Type> GetExportServiceTypes(Type targetType)
118118
{
119+
if (targetType.IsAbstract && targetType.IsSealed)
120+
{
121+
throw new ArgumentException($"Can not export service from static class {targetType}");
122+
}
123+
119124
TargetType = targetType;
120125

121126
if (ExportTypeDiscovererType is null)
@@ -128,7 +133,14 @@ public virtual IEnumerable<Type> GetExportServiceTypes(Type targetType)
128133
if (types is null
129134
|| !types.Any())
130135
{
131-
throw new ModularityException($"Can not get export service for type {targetType} automatically . Must use {nameof(ExportServicesAttribute)} define it clearly .");
136+
if (targetType.GetInterfaces().IsNullOrEmpty())
137+
{
138+
types = new[] { targetType };
139+
}
140+
else
141+
{
142+
throw new ModularityException($"Can not get export service for type {targetType} automatically . Must use {nameof(ExportServicesAttribute)} define it clearly .");
143+
}
132144
}
133145
else if (types.Length > 1)
134146
{

src/Cuture.Extensions.Modularity/Internal/Extensions/ArrayExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static class ArrayExtensions
1313
/// <param name="array"></param>
1414
/// <returns></returns>
1515
[MethodImpl(MethodImplOptions.AggressiveInlining)]
16-
public static bool IsNullOrEmpty<T>(this T[] array)
16+
public static bool IsNullOrEmpty<T>(this T[]? array)
1717
{
1818
return array is null
1919
|| array.Length == 0;

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<!--Package Info-->
3131
<PropertyGroup>
32-
<VersionPrefix>1.1.6</VersionPrefix>
32+
<VersionPrefix>1.1.7</VersionPrefix>
3333

3434
<PackageIdPrefix>Cuture.Extensions</PackageIdPrefix>
3535
<Authors>Stratos</Authors>

0 commit comments

Comments
 (0)