I want to enumerate all types in large app and find all classes implementing IFoo
Using Skeet answer to similar question
var types = (from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
where Attribute.IsDefined(type, typeof(SerializableAttribute))
select type).ToList();
I see how to do this but a couple of comments I saw make me doubt when I can do this.
When will the list be complete. I mean at what point in the appdomain lifecycle are all the assemblies loaded. Obviously dynamically loaded ones are not loaded immediately, but what about static ones. Is the loading deferred until first use? My original solution to the requirement involved static constructors but that suffers from the problem that these are lazily called.