我有一个方法如下
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...
}
现在我想重构代码,使 solutionPrefix 参数是一个字符串数组,在第一个 Where 子句中,它选择名称以solutionPrefix 数组。
最佳答案
您可以使用 Any
的重载扩展方法。
.Where(x => solutionPrefix.Any(e => x.FullName.StartsWith(e)))
关于c# - 内部 LINQ 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49475234/