coderush - 如何在 CodeRush 中获取实现接口(interface)的类?

标签 coderush dxcore

我试图编写一个返回实现接口(interface)的类列表的方法,但无法实现。

类似的方法

  public List<Class> GetImplementedClasses(Interface Interface1)
   {
        . . . 
   }

我尝试使用 interface1.AllChildren 和许多其他尝试。他们都没有给出任何结果。

是否可以使用 DXCore API 编写这样的方法?

示例:

enter image description here

如果我传递 Interface1,我应该从方法 GetImplementedClasses 中获取 Class1 和 Class2。

提前致谢。

最佳答案

在 Intrerface 类中有一个“GetDescendants”方法可能对您的任务有用。代码看起来类似于:

public List<Class> GetImplementedClasses(Interface Interface1)
{
  List<Class> result = new List<Class>();
  if (Interface1 != null)
  {
    ITypeElement[] descendants = Interface1.GetDescendants();
    foreach (ITypeElement descendant in descendants)
    {
      if (!descendant.InReferencedAssembly)
      {
        Class classDescendant = descendant.ToLanguageElement() as Class;
        if (classDescendant != null)
          result.Add(classDescendant);
      }
    }
  }
  return result;
}

关于coderush - 如何在 CodeRush 中获取实现接口(interface)的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6539913/

相关文章:

coderush - 如何使用 DXCore 获取类中的所有方法并存储在文件中?

c# - 我为什么要购买 ReSharper 或 CodeRush?

performance - ReSharper VS CodeRush性能

coderush - 我可以使用 CodeRush Express 编写插件并使用它吗?

c# - 使用DXCore控制台应用程序获取解决方案/项目中的文件列表

.net - 禁用 CodeRush

visual-studio-2010 - 如何扩展 IntelliSense 项?

visual-studio - 为什么我应该从 ReSharper 切换到 CodeRush?