Getting all the classes in project and their packages from CodeRush extension

血红的双手。 提交于 2019-12-04 18:11:33

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!