我試圖更新現有的C#代碼。該代碼使用ICSharpCode.NRefactory.IParser
進行解析。我的系統正在廣泛使用ICompilationUnit
來探索現有的代碼。如何從ICompilationUnit(ICSharpCode)生成C#代碼
現在,我想添加一個方法到現有的文件,並將其保存回磁盤作爲C#代碼。到目前爲止,我有:
CompilationUnit compilationUnit = GetCompilationUnit();
var visitor = new NRefactoryASTConvertVisitor(new ParseProjectContent());
compilationUnit.AcceptVisitor(visitor, null);
IMethod method = //GetMethod from otherplace
visitor.Cu.Classes[0].Methods.Add(method);
// How the updated visitor.Cu be transformed to C# code
我希望做的是從visitor.Cu
生成C#代碼。有沒有辦法從ICompilationUnit
生成C#代碼?