c#assembly.GetExportedTypes

时间:2018-03-31 13:41:38

标签: c# reflection gettype

我正在尝试获取继承自另一个类的类链中最低类(G)的类型,如下所示。

1。public class G: F

2。public class F: E<STate>

3。public abstract class E<TState> : D<TState, StatusQueryParams> where TState : E, new()

4。public abstract class D<TState, TQuery> :C<TState, TQuery>

5。public abstract class C<TState, TQuery> : IA, IB

6。public interface IA: IB

此外,我只知道IA的类型,其余的都是不断变化的客户代码。因此,知道IA的类型我应该获得G

的类型

目前我正在使用:

var classtype= assembly.GetExportedTypes().Where(t =>
typeof(IA).IsAssignableFrom(t) && t.IsClass && !t.IsAbstract);

由于某些原因,这对我不起作用。

1 个答案:

答案 0 :(得分:0)

try using this i will help

    public class IA
    {
       public static void Main()
       {
          foreach (var t in typeof(IA).Assembly.GetTypes()) {
             Console.WriteLine("{0} derived from: ", t.FullName);
             var derived = t;
             do { 
                derived = derived.BaseType;
                if (derived != null) 
                   Console.WriteLine("   {0}", derived.FullName);

             } while (derived != null);
             Console.WriteLine(); 
          } enter code here
       }