【发布时间】:2010-12-01 16:53:31
【问题描述】:
如何在代码编辑器中从扩展中添加/删除代码?
例如:
我创建了一个扩展,女巫修改来自传入套接字的代码
该示例使用 Microsoft.VisualStudio.Text.Editor
尝试使用:
IWpfTextView textView; // got from visual studio "Create" event
ITextChange change; // Got from network socket or other source
ITextEdit 编辑 = textView.TextBuffer.CreateEdit(); // 抛出“非所有者”异常 编辑.删除(更改.OldSpan); 编辑.插入(更改。新位置,更改。新文本);
但我想还有另一种方法,因为 CrateEdit() 函数失败
【问题讨论】:
-
你能发布完整的错误信息吗?
-
错误:试图在错误的线程上编辑 TextBuffer。和“textView.TextBuffer.TakeThreadOwnership();” throws: 试图改变 TextBuffer 的编辑线程。
标签: .net visual-studio vsix