【问题标题】:c# assembly.GetExportedTypes时间:2019-04-10 标签:c#assembly.GetExportedTypes
【发布时间】:2018-09-10 07:41:13
【问题描述】:

我正在尝试获取从另一个继承的类链中最低类的类型 (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);

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

【问题讨论】:

    标签: c# reflection gettype


    【解决方案1】:
    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
           }
    

    【讨论】:

      猜你喜欢
      • 2016-04-19
      • 2022-01-16
      • 2018-07-04
      • 2019-06-02
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 2015-02-10
      • 2013-06-03
      相关资源
      最近更新 更多