I’m missing something but not sure what it is. I would like to implement this method, so it scan’s the assembly containing the provided type and add them to the container.
the problem is: How do i add the types that are returned from my query to the collection of scanners?
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;
}
The TorrentScannerContainer.Current.Scannners is a collection of ITorrentScanner:
internal List<ITorrentScanner> Scanners { get; private set; }
I hope someone can help me out!
Well, the problem is you try to add types in a collection of ITorrentScanner. You should either have a list of types in scanners, or create an instance of the type :
Of course, this means your type has a default constructor. If this is not the case, then I don’t know how to instanciate them… but certainly you do