lundi 17 décembre 2018

How To List Types in Assembly or Namespace that have been created at run-time using MakeGenericType?

Consider the following two types:

public abstract class Abase {
}

public class MyGeneric<T> : Abase {
}

If I create a Type at runtime using MakeGenericType:
How can I query the assembly or namespace later for that type?

var paramType = typeof (string);
var myMiscType = typeof (MyGeneric<>).MakeGenericType(paramType);

var assembly = myMiscType.Assembly;
//my type is not in here:
var allTypesfromMyTypeAssembly = (
        from t in assembly.GetTypes()where typeof (Abase).IsAssignableFrom(t)select t);

.Net Fiddle

I tried a few things, but none seem to work. Is what I want Possible?





Aucun commentaire:

Enregistrer un commentaire