0

In a VS2010 package, I have a piece of code that calls FileCodeModel.CodeElements, when the caret position changes. Also I registered a handler in the CodeModelEvents bound to the document.

When the package monitors a C# project, it works OK. However, when monitoring a VB project, the FileCodeModel.CodeElements call fails with an COMException that corresponds to an E_FAIL error.

any ideas why the behavior is different?

4

1 に答える 1

2

C# と VB.net のコード モデルは完全に別個の実装であり、どちらにも関連する癖があります。

VB.Net では、キャレット位置の変更は、IDE で行コミット ロジックをトリガーできる、より大きな一連のイベントの一部です。特にバッファがダーティな場合に、この特定のイベントがスローされることには特に驚きはありません。

これを回避する 1 つの方法は、キャレットの移動後にアイドル イベントを待機し、CodeElementsそこでクエリを実行することです。

于 2012-02-04T00:13:00.573 に答える