Skip to content

Commit df99e17

Browse files
committed
Use collection expressions
1 parent 2dba71f commit df99e17

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/Scrutor/ServiceTypeSelector.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public ServiceTypeSelector(IImplementationTypeSelector inner, ISet<Type> types)
2020

2121
private ISet<Type> Types { get; }
2222

23-
private List<ISelector> Selectors { get; } = new();
23+
private List<ISelector> Selectors { get; } = [];
2424

2525
private RegistrationStrategy? RegistrationStrategy { get; set; }
2626

2727
public ILifetimeSelector AsSelf()
2828
{
29-
return As(t => new[] { t });
29+
return As(t => [t]);
3030
}
3131

3232
public ILifetimeSelector As<T>()
@@ -45,7 +45,7 @@ public ILifetimeSelector As(IEnumerable<Type> types)
4545
{
4646
Preconditions.NotNull(types, nameof(types));
4747

48-
return AddSelector(Types.Select(t => new TypeMap(t, types)), Enumerable.Empty<TypeFactoryMap>());
48+
return AddSelector(Types.Select(t => new TypeMap(t, types)), []);
4949
}
5050

5151
public ILifetimeSelector AsImplementedInterfaces()
@@ -70,7 +70,7 @@ public ILifetimeSelector AsSelfWithInterfaces(Func<Type, bool> predicate)
7070
Preconditions.NotNull(predicate, nameof(predicate));
7171

7272
return AddSelector(
73-
Types.Select(t => new TypeMap(t, new[] { t })),
73+
Types.Select(t => new TypeMap(t, [t])),
7474
Types.Select(t => new TypeFactoryMap(t, x => x.GetRequiredService(t), Selector(t, predicate))));
7575

7676
static IEnumerable<Type> Selector(Type type, Func<Type, bool> predicate)
@@ -79,7 +79,7 @@ static IEnumerable<Type> Selector(Type type, Func<Type, bool> predicate)
7979
{
8080
// This prevents trying to register open generic types
8181
// with an ImplementationFactory, which is unsupported.
82-
return Enumerable.Empty<Type>();
82+
return [];
8383
}
8484

8585
return GetInterfaces(type).Where(predicate);
@@ -100,7 +100,7 @@ public ILifetimeSelector As(Func<Type, IEnumerable<Type>> selector)
100100
{
101101
Preconditions.NotNull(selector, nameof(selector));
102102

103-
return AddSelector(Types.Select(t => new TypeMap(t, selector(t))), Enumerable.Empty<TypeFactoryMap>());
103+
return AddSelector(Types.Select(t => new TypeMap(t, selector(t))), []);
104104
}
105105

106106
public IImplementationTypeSelector UsingAttributes()

src/Scrutor/TypeSourceSelector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public class TypeSourceSelector : ITypeSourceSelector, ISelector
1212
private static Assembly EntryAssembly => Assembly.GetEntryAssembly()
1313
?? throw new InvalidOperationException("Could not get entry assembly.");
1414

15-
private List<ISelector> Selectors { get; } = new();
15+
private List<ISelector> Selectors { get; } = [];
1616

1717
/// <inheritdoc />
1818
public IImplementationTypeSelector FromAssemblyOf<T>()
1919
{
20-
return InternalFromAssembliesOf(new[] { typeof(T) });
20+
return InternalFromAssembliesOf([typeof(T)]);
2121
}
2222

2323
/// <summary>

test/Scrutor.Tests/ScanningTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void CanCreateDefault()
307307

308308
var remainingSetOfTypes = Collection
309309
.Select(descriptor => descriptor.ServiceType)
310-
.Except(types.Concat(new[] { typeof(DefaultAttributes) }))
310+
.Except(types.Concat([typeof(DefaultAttributes)]))
311311
.ToList();
312312

313313
Assert.Equal(5, Collection.Count);

0 commit comments

Comments
 (0)