Skip to content

Commit 2c449ac

Browse files
committed
code style chore
1 parent 3092f3c commit 2c449ac

24 files changed

Lines changed: 41 additions & 55 deletions

samples/OtherModuleSystemAdaptSample/AbpAdaptedServiceRegistrar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class AbpAdaptedServiceRegistrar : DefaultServiceRegistrar
1616
{
1717
private Volo.Abp.DependencyInjection.DefaultConventionalRegistrar _defaultConventionalRegistrar = new();
1818

19-
private readonly HashSet<Assembly> _processedAssemblies = new HashSet<Assembly>();
19+
private readonly HashSet<Assembly> _processedAssemblies = [];
2020

2121
public override void AddAssembly(IServiceCollection services, Assembly assembly)
2222
{

src/Cuture.Extensions.Modularity.Hosting/DefaultOptionsBinder.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class DefaultOptionsBinder : IOptionsBinder
3333
public DefaultOptionsBinder(OptionsBindOptions options)
3434
{
3535
AutoBindOptions = options ?? throw new ArgumentNullException(nameof(options));
36-
_optionsExtensionMethod = typeof(OptionsConfigurationServiceCollectionExtensions).GetMethod("Configure", new[] { typeof(IServiceCollection), typeof(IConfiguration) })!;
36+
_optionsExtensionMethod = typeof(OptionsConfigurationServiceCollectionExtensions).GetMethod("Configure", [typeof(IServiceCollection), typeof(IConfiguration)])!;
3737
}
3838

3939
#endregion Public 构造函数
@@ -43,12 +43,8 @@ public DefaultOptionsBinder(OptionsBindOptions options)
4343
/// <inheritdoc/>
4444
public virtual void BindOptionsInAssembly(IServiceCollection services, Assembly assembly)
4545
{
46-
var configuration = services.GetConfiguration();
47-
48-
if (configuration is null)
49-
{
50-
throw new ModularityException($"Cannot auto bind options with out any {nameof(IConfiguration)} in {nameof(IServiceCollection)}");
51-
}
46+
var configuration = services.GetConfiguration()
47+
?? throw new ModularityException($"Cannot auto bind options with out any {nameof(IConfiguration)} in {nameof(IServiceCollection)}");
5248

5349
services.AddOptions();
5450

@@ -105,12 +101,8 @@ protected virtual IEnumerable<Type> FindOptionsTypes(Assembly assembly)
105101
/// <returns></returns>
106102
protected virtual IConfigurationSection GetOptionsConfiguration(IConfiguration configuration, Type optionsType)
107103
{
108-
var targetConfigurationKey = GetOptionsConfiguretionSectionKey(optionsType);
109-
110-
if (targetConfigurationKey is null)
111-
{
112-
throw new ModularityException($"cannot auto find {nameof(IConfiguration)} for option type {optionsType}.cannot auto bind it.");
113-
}
104+
var targetConfigurationKey = GetOptionsConfiguretionSectionKey(optionsType)
105+
?? throw new ModularityException($"cannot auto find {nameof(IConfiguration)} for option type {optionsType}.cannot auto bind it.");
114106

115107
var targetConfiguration = configuration.GetSection(targetConfigurationKey);
116108
return targetConfiguration;

src/Cuture.Extensions.Modularity.Hosting/HostBuilderModuleLoadContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ internal sealed class HostBuilderModuleLoadContext
44
{
55
#region Private 字段
66

7-
private readonly List<KeyValuePair<IModuleSource, Action<ModuleLoadOptions>?>> _moduleSources = new();
8-
private readonly List<Action<ModuleLoadOptions>> _optionActions = new();
7+
private readonly List<KeyValuePair<IModuleSource, Action<ModuleLoadOptions>?>> _moduleSources = [];
8+
private readonly List<Action<ModuleLoadOptions>> _optionActions = [];
99

1010
#endregion Private 字段
1111

src/Cuture.Extensions.Modularity/AggregatedModuleDescriptorBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class AggregatedModuleDescriptorBuilder : IModuleDescriptorBuilder
2525
/// <inheritdoc cref="AggregatedModuleDescriptorBuilder"/>
2626
public AggregatedModuleDescriptorBuilder()
2727
{
28-
_descriptorBuilders = new List<IModuleDescriptorBuilder>()
29-
{
28+
_descriptorBuilders =
29+
[
3030
DefaultModuleDescriptorBuilder.Default
31-
};
31+
];
3232
}
3333

3434
#endregion Public 构造函数

src/Cuture.Extensions.Modularity/AggregatedModulesBootstrapInterceptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public AggregatedModulesBootstrapInterceptor(IEnumerable<IModulesBootstrapInterc
3131
{
3232
if (interceptors is null)
3333
{
34-
_modulesBootstrapInterceptors = new List<IModulesBootstrapInterceptor>();
34+
_modulesBootstrapInterceptors = [];
3535
}
3636
else
3737
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public virtual IEnumerable<Type> GetExportServiceTypes(Type targetType)
127127
}
128128
var types = targetType.GetMostLikelyDirectInterfacesExcludeDefaults()?.ToArray();
129129
if (types is null
130-
|| !types.Any())
130+
|| types.Length == 0)
131131
{
132132
if (targetType.GetInterfaces().IsNullOrEmpty())
133133
{

src/Cuture.Extensions.Modularity/Contexts/ApplicationInitializationContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public ApplicationInitializationContext(IServiceProvider serviceProvider, IDicti
2525
{
2626
ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
2727
Items = items is null
28-
? new Dictionary<string, object?>()
28+
? []
2929
: new Dictionary<string, object?>(items);
3030
}
3131

src/Cuture.Extensions.Modularity/Contexts/AutoRegisterModuleServicesContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AutoRegisterModuleServicesContext
1414
/// <summary>
1515
/// 已处理的程序集
1616
/// </summary>
17-
public HashSet<Assembly> ProcessedAssemblies { get; } = new HashSet<Assembly>();
17+
public HashSet<Assembly> ProcessedAssemblies { get; } = [];
1818

1919
/// <summary>
2020
///

src/Cuture.Extensions.Modularity/Contexts/StoreableContextBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class StoreableContextBase
1010
/// <summary>
1111
/// 储存的传递项
1212
/// </summary>
13-
public Dictionary<string, object?> Items { get; protected set; } = new();
13+
public Dictionary<string, object?> Items { get; protected set; } = [];
1414

1515
#endregion Public 属性
1616

src/Cuture.Extensions.Modularity/Extensions/IEnumerableSortByDependenciesExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public static T[] SortByDependencies<T>(this IEnumerable<T> source, Func<T, IEnu
2525
return Array.Empty<T>();
2626
}
2727

28-
List<T> sorted = new();
29-
Dictionary<T, bool> visited = new();
28+
List<T> sorted = [];
29+
Dictionary<T, bool> visited = [];
3030

3131
foreach (var item in source)
3232
{

0 commit comments

Comments
 (0)