順便說一句,它看起來像羅裏已經固定在「Refactor_Resolver」插件的一些錯誤和現在的工作。至於你的問題,這裏有一個快速回復:
RE#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:要在彈出的設置它的「CodeIssueMessage」屬性添加一個CodeProvider的代碼問題的名義來解決,例如
myCodeProvider.CodeIssueMessage =「Undeclared element」;
讓我知道你是否需要進一步的幫助。
很好的答案!謝謝。您的代碼允許在插件加載時構建插件的內部緩存。因爲CodeRush的緩存會更簡單 - 它只包含每個對象('Class','Interface' ...)的'String',可以從項目類中引用。然而這可能是長時間運行的任務。它適合在插件啓動時運行,但每次使用代碼提供程序時我都無法掃描所有可用的類。如果我可以註冊某些事件來通知我有關新的(或刪除的)類或引用的信息,那麼我就不必重新掃描了。 – drasto 2010-05-25 21:38:36