-
Book Overview & Buying
-
Table Of Contents
Metaprogramming in C#
By :
In Chapter 4, Reasoning about Types Using Reflection, we introduced a class called Types, which encapsulates the logic used in finding types. This is a very powerful construct for enabling software to be extensible. We can make it a little bit better and build a construct on top of it that simplifies its use.
In the Types class, we have a method called FindMultiple(), which allows us to find types that implement a specific type. A small improvement on this would be to allow us to represent the different types we want implementations of by taking a dependency in a constructor of a specific type that describes this.
Important note
You’ll find the implementation of this in the Fundamentals part of the repository mentioned in the Technical requirements section.
The concept is basically to have the type represented as an interface, as follows:
public interface IImplementationsOf<T> : IEnumerable<Type> ...