【发布时间】:2010-11-07 00:22:55
【问题描述】:
我写了一个小插件,它对我的 C# 代码进行了一些格式化。 在插件 Exec 方法中,我执行以下操作
try {
TextSelection selection = (EnvDTE.TextSelection)_applicationObject.ActiveDocument.Selection;
String foo = String.Empty;
if (!text.IsEmpty) {
foo = someCoolObjectThatFormatsText.Format(selection.Text);
selection.Text = foo; // here everything gets painfully slow :-(
}
}
catch (Exception) {
throw;
}
当行带有代码“SelectedText.Text = foobar;”是调用,VS一步一步重建选择的每一行。您可以轻松地观看它执行此步骤。但我不明白,为什么这么慢。
有什么提示吗? TIA
【问题讨论】:
-
呃,我猜你的 'foobar' 应该是 'foo',因为我没有看到事先定义的 'foobar'。
-
你当然是对的。修好了。
-
摆脱 try/catch。它什么也没做,因为你所做的只是“扔”;
-
你是对的,但在真正的插件中,异常是被处理的......
标签: c# visual-studio code-formatting vsx visual-studio-addins