顺便说一句,看起来 Rory 已经修复了“Refactor_Resolver”插件中的一些错误,它现在可以工作了。至于您的问题,这里有一个快速回复:
回复 #1:
CodeRush 有一个内置缓存,用于在解析解决方案时构建的所有类型、项目引用等。但目前它是在内部使用的,并没有暴露给插件开发者,对不起。但是,这里有一些有用的 API 可供入门:
// 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: ...
}
}
要获取程序集引用缓存,请使用 ScopeManager(位于 DevExpress.DXCore.MetaData.dll 中),例如
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:要将 CodeProvider 添加到弹出窗口,请将其“CodeIssueMessage”属性设置为要修复的代码问题的名称,例如
myCodeProvider.CodeIssueMessage = "未声明的元素";
如果您需要进一步的帮助,请告诉我。