-
Notifications
You must be signed in to change notification settings - Fork 4
Reflection
Reflection is its name advice, is collection of extensions for System.Reflection. The most interesting type here is IReflectionService which can be created by ReflectionFactory.
IReflectionService is collection of extensions for app domain and assemblies and types loaded into it.
When you have IReflectionService for selected app domain, you can load assembly into by calling LoadAssembly. In default implementation, this is done by reading array of bytes from file system defining the assembly and than pushing this array into application as assembly. This doesn't lock the underlaying assembly file so this can be deleted, re-generated or what ever.
Another interesting method is PrepareTypeExecutors which creates ITypeExecutorService. This service enables to register component, that will be called on every type that is loaded into app domain. By passing second parameter set to true, this component will be also called on every type lately loaded into app domain.
One implementation of this component, called FilterTypeExecutor, enables to register filters and executors (using delegates) that will be executed on these app domain types. So, reusing filters like 'exclude abstract classes' or 'exclude types without default constructor' you can easily enumerate only those types, that fits actual requiremenets. This feature by, for e.g., used for auto-loading converters from all types in app domain.
...
ITypeExecutorService service = ...;
service
.AddFiltered()
.AddFilterNotInterface()
.AddFilterNotAbstract()
.AddFilterHasDefaultConstructor()
.AddFilterHasAttribute<ConverterAttribute>()
.AddHandler(t => AddConverter(repository, t));
...