我错过了一些东西,但不确定它是什么。我想实现这个方法,所以它扫描包含所提供类型的程序集并将它们添加到容器中。
问题是:如何将查询返回的类型添加到扫描仪集合中?
public TorrentScannerContainer AddFromAssemblyOf<T>()
{
TorrentScannerContainer current;
lock (TorrentScannerContainer._padlock)
{
var assignableType = typeof(ITorrentScanner);
var scanners = AppDomain.CurrentDomain.GetAssemblies().ToList()
.SelectMany(x => x.GetTypes())
.Where(t => assignableType.IsAssignableFrom(t) && t.IsClass).ToList();
foreach (Type type in scanners)
{
var scanner = type as ITorrentScanner;
TorrentScannerContainer.Current.Scanners.Add(scanner);
}
current = TorrentScannerContainer.Current;
}
return current;
}
TorrentScannerContainer.Current.Scannners 是 ITorrentScanner 的集合:
internal List<ITorrentScanner> Scanners { get; private set; }
我希望有人可以帮助我!