gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:56:35 25 4
gpt4 key购买 nike

我试图编写一个返回实现接口(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com