实现参见:https://github.com/lukebuehler/NRefactory-Completion-Sample
智能提示:关键代码片段
//editor初始化
editor.Completion=new ICSharpCode.CodeCompletion.CSharpCompletion(GetRelativeAssemblies());
//需要支持提示的DLL在此处加载
private Assembly[] GetRelativeAssemblies()
{
return new Assembly[] {
typeof(object).Assembly, //mscorlib
typeof(Uri).Assembly, //System.dll
typeof(Enumerable).Assembly,//System.Core.dll
};
}
//注意:此处若直接采用 editor.Text 赋值,则智能提示无法使用
editor.OpenFile("../../Program.cs");
editor.Text = "using System;";
//editor.NewFile("Program.cs", "using System;");
关于 editor.Text 赋值无法使用智能提示原因见 CodeTextEditor.cs
//only process csharp files and if there is a code completion engine available
if (String.IsNullOrEmpty(Document.FileName))
{
Debug.WriteLine("No document file name, cannot run code completion");
return;
}
代码折叠:关键代码片段
//editor初始化