Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimize finding all classes implementing IInterface<T> and those explicitly implementing it with a specific type
    primarykey
    data
    text
    <p>I have an interface ISerializeDeserialize defined and some classes inheriting the generic interface. I also have some code generated assemblies using the CodeDomProvider which generates classes inherited from the same interface but implementing it with a specific Type.</p> <p>What I want to achieve is getting a list of the generic implementations and those implementing the specific type. You can let T=int in the code below.</p> <p>To get all classes implementing ISerializeDeserialize of some type I so far have this code:</p> <pre><code>private List&lt;Type&gt; GetListOfGenericSerializers() { Type interfaceGenricType = typeof(ISerializeDeserialize&lt;T&gt;); var serializers = from assembly in AppDomain.CurrentDomain.GetAssemblies() from genericType in assembly.GetTypes() from interfaceType in genericType.GetInterfaces() .Where(iType =&gt; (iType.Name == interfaceGenricType.Name &amp;&amp; genericType.IsGenericTypeDefinition)) select genericType; return serializers.ToList(); } private List&lt;Type&gt; GetListOfTypeImplementedSerializers() { Type interfaceGenricType = typeof(ISerializeDeserialize&lt;T&gt;); var serializers = from assembly in AppDomain.CurrentDomain.GetAssemblies() from implementedType in assembly.GetTypes() from interfaceType in implementedType.GetInterfaces() .Where(iType =&gt; iType == interfaceGenricType) select implementedType; return serializers.ToList(); } </code></pre> <p>I could pull them together in one function, but I use two for clarity. Question is, can this be optimized or is it done in a better way?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload