【问题标题】:How do I get information on a base element? .Children throws NotImplementedException如何获取有关基本元素的信息? .Children 抛出 NotImplementedException
【发布时间】:2012-08-20 15:48:21
【问题描述】:

我正在使用 Visual Studio 的 CodeModel 来收集代码中的接口信息。

我能够使用CodeInterface 类型成功收集有关接口的信息。这个接口公开了一个属性 Bases,它允许我发现我的接口继承自哪些接口。

但是,虽然我可以使用.Children 逐步浏览初始界面的属性或方法。我不能对父接口做同样的事情(NotImplementedException 被抛出)。

最初我认为这个问题是因为我使用的是FileCodeModel,所以我切换到Project.CodeModel

FileCodeModel fileCM =  
        _applicationObject.ActiveDocument.ProjectItem.FileCodeModel;

我的代码:

CodeModel CM = _applicationObject.ActiveWindow.Project.CodeModel;

CodeInterface myInterface = 
    (CodeInterface)CM.CodeTypeFromFullName( "ConsoleApplication8.IWrapper" );

foreach( CodeElement cE in myInterface.Bases ) {
    if( cE is CodeInterface ) {
        string itemName = cE.FullName;
        CodeInterface parentInterface = 
        (CodeInterface)CM.CodeTypeFromFullName( itemName );
    }
}

【问题讨论】:

    标签: c# visual-studio visual-studio-extensions c#-code-model


    【解决方案1】:

    原来要使用的CodeInterface 的正确属性是.Members(它仍然是CodeElements 的可枚举集)

    【讨论】:

      猜你喜欢
      • 2021-01-17
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 2014-02-22
      相关资源
      最近更新 更多