Skip to content

Commit

Permalink
Use collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
khellang committed Dec 23, 2024
1 parent 2dba71f commit df99e17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/Scrutor/ServiceTypeSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public ServiceTypeSelector(IImplementationTypeSelector inner, ISet<Type> types)

private ISet<Type> Types { get; }

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

private RegistrationStrategy? RegistrationStrategy { get; set; }

public ILifetimeSelector AsSelf()
{
return As(t => new[] { t });
return As(t => [t]);
}

public ILifetimeSelector As<T>()
Expand All @@ -45,7 +45,7 @@ public ILifetimeSelector As(IEnumerable<Type> types)
{
Preconditions.NotNull(types, nameof(types));

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

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

return AddSelector(
Types.Select(t => new TypeMap(t, new[] { t })),
Types.Select(t => new TypeMap(t, [t])),
Types.Select(t => new TypeFactoryMap(t, x => x.GetRequiredService(t), Selector(t, predicate))));

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

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

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

public IImplementationTypeSelector UsingAttributes()
Expand Down
4 changes: 2 additions & 2 deletions src/Scrutor/TypeSourceSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class TypeSourceSelector : ITypeSourceSelector, ISelector
private static Assembly EntryAssembly => Assembly.GetEntryAssembly()
?? throw new InvalidOperationException("Could not get entry assembly.");

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

/// <inheritdoc />
public IImplementationTypeSelector FromAssemblyOf<T>()
{
return InternalFromAssembliesOf(new[] { typeof(T) });
return InternalFromAssembliesOf([typeof(T)]);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion test/Scrutor.Tests/ScanningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void CanCreateDefault()

var remainingSetOfTypes = Collection
.Select(descriptor => descriptor.ServiceType)
.Except(types.Concat(new[] { typeof(DefaultAttributes) }))
.Except(types.Concat([typeof(DefaultAttributes)]))
.ToList();

Assert.Equal(5, Collection.Count);
Expand Down

0 comments on commit df99e17

Please sign in to comment.