获取项目的所有类及其包装从扩展的CodeRush [英] Getting all the classes in project and their packages from CodeRush extension

查看:156
本文介绍了获取项目的所有类及其包装从扩展的CodeRush的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间,试图找到一种方式的CodeRush可以添加使用时,发现未申报的元素,它是在事实类的名字,没有使用补充说。该解决方案在提出这个答案我的问题(的 Refactor_resolve )不起作用(窃听)



在一个过程中,我发现,编写插件的CodeRush是容易的,所以我决定编写这个功能我自己(和共享)。我只实施 CodeProvider (类似的本教程)。唯一觉得我需要做的工作是回答这个问题:




  1. 在开始了我的插件,我需要
    ,来获得
    的所有类和包的列表(集,地图,等等)。这种
    指所有引用的库中的所有类(接口...)
    和他们的项目包和
    。和
    我还需要接收更新的
    本(当用户添加引用,
    创建新类)。 我得到这个从一定的CodeRush类或者VS从 CodeProvider 类可用的接口?


  2. 如何添加创建 CodeProvider 当用户将鼠标悬停在一个问题,显示弹出?



解决方案

顺便说一句,它看起来像罗里已固定在Refactor_Resolver一些错误插件在和现在的工作。至于你的问题,这里有一个快速回复:



RE#1:



的CodeRush有一个内置的缓存对于所有类型的,项目的引用等,虽然溶液是解析构建。但此刻它在内部,而不是用于暴露插件的开发者,对不起。但是,这里有开始使用一些有用的API:

  //使用源代码缓存... 

//获取活动方案对象
SolutionElement activeSolution = CodeRush.Source.ActiveSolution;
如果(activeSolution == NULL)
的回报;

//迭代思想在解决
的foreach的所有项目(在activeSolution.AllProjects ProjectElement项目)
{
字符串的AssemblyName = project.AssemblyName;

//遍历源代码符号缓存...
Hashtable的projectSymbols = activeProject.ProjectSymbols内;
的foreach(在projectSymbols.Values对象的项目)
{
ITypeElement typeElement =项目作为ITypeElement;
如果(typeElement == NULL)
继续;

// TODO:...
}
}

要获得集引用缓存,使用ScopeManager(位于DevExpress.DXCore.MetaData.dll),如:

  IEnumerable的< IMetaDataScope> allMetaDataScopes = ScopeManager.All; 
的foreach(在allMetaDataScopes IMetaDataScope范围内)
{
IAssemblyInfo装配= scope.Assembly;
如果(组装!= NULL)
{
的ITypeInfo [] =类型assembly.GetTypes();
的for(int i = 0; I< types.Length;我++)
{
的ITypeInfo所属类别=类型[I]
如果(所属类别== NULL)
继续;

// TODO:...
}
}
}

RE#2:向CodeProvider添加到弹出设置其CodeIssueMessage属性的代码问题的名义来解决,如:



myCodeProvider.CodeIssueMessage =未声明的元素。



让我知道如果你需要进一步的帮助。


I've spent some time trying to find a way CodeRush could add using when it finds undeclared element that is in the fact class name with no using added. The solution suggested in this answer to my question (Refactor_resolve) does not work (bugged?).

In a process I found out that writing plug-ins for CodeRush is easy, so I decided to code this functionality myself (and share it). I'd only implement a CodeProvider (like in this tutorial). The only thinks I need to do the job are answers to this questions:

  1. At the start up of my plugin I need to get a list (set, map, whatever) of all classes and their packages. This means all the classes(interfaces...) and their packages in project, and within all referenced libraries. And I also need to receive updated on this (when user adds reference, creates new class). Can I get this from some CodeRush classes or maybe VS interface available from CodeProvider class?

  2. How do I add created CodeProvider to the pop-up that is shown when user hovers over an Issue?

解决方案

BTW, it looks like Rory has fixed some bugs in the "Refactor_Resolver" plug-in and it works now. As for your questions here's a quick reply:

RE #1:

CodeRush has a built-in cache for all types, project references, etc that is built while the solution is parsing. But at the moment it is used internally and not exposed for plug-in devs, sorry. However, here are some useful APIs to get started with:

  // Using the source code cache...

  // gets the active Solution object
  SolutionElement activeSolution = CodeRush.Source.ActiveSolution;
  if (activeSolution == null)
    return;

  // iterate thought all projects in the solution
  foreach (ProjectElement project in activeSolution.AllProjects)
  {
    string assemblyName = project.AssemblyName;

    // iterate inside source code symbols cache...
    Hashtable projectSymbols = activeProject.ProjectSymbols;
    foreach (object item in projectSymbols.Values)
    {
      ITypeElement typeElement = item as ITypeElement;
      if (typeElement == null)
        continue;

      // TODO: ...
    }
  }

To get assembly references cache, use a ScopeManager (located in DevExpress.DXCore.MetaData.dll), e.g.

  IEnumerable<IMetaDataScope> allMetaDataScopes = ScopeManager.All;
  foreach (IMetaDataScope scope in allMetaDataScopes)
  {
    IAssemblyInfo assembly = scope.Assembly;
    if (assembly != null)
    {
      ITypeInfo[] types = assembly.GetTypes();
      for (int i = 0; i < types.Length; i++)
      {
        ITypeInfo typeInfo = types[i];
        if (typeInfo == null)
          continue;

        // TODO: ...
      }
    }
  }

RE #2: To add a CodeProvider to the pop-up set its "CodeIssueMessage" property to the name of the code issue to fix, e.g.

myCodeProvider.CodeIssueMessage = "Undeclared element";

Let me know if you need further assistance.

这篇关于获取项目的所有类及其包装从扩展的CodeRush的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆