Milad
Milad

Reputation: 592

Inner LINQ query

I have a method as follow

private void RegisterServices(IServiceCollection serviceCollection, Container container, string solutionPrefix)
{
   var types = AppDomain.CurrentDomain.GetAssemblies()
                .Where(a.FullName.StartsWith(solutionPrefix))
                .SelectMany(x => x.GetTypes())
                .Where(x => !x.IsAbstract && !x.IsGenericTypeDefinition);
   //Rest of the code...
}

Now I want to refactor the code in a way that solutionPrefix parameter is an array of strings and in the first Where clause it selects all the assemblies that their name starts with any of the items in the solutionPrefix array.

Upvotes: 1

Views: 46

Answers (1)

Ousmane D.
Ousmane D.

Reputation: 56423

You can use this overload of the Any extension method.

.Where(x => solutionPrefix.Any(e => x.FullName.StartsWith(e)))

Upvotes: 5

Related Questions