私はそれを理解しました。情報を共有することもあります。
SVsShellMonitorSelection
サービスを使用すると、選択した階層への参照をIVsHierarchy
として取得できます。これにより、選択したオブジェクトへの参照を取得できます。ソリューションエクスプローラで選択した内容に基づいて、Project
,ProjectItem
などのクラスにキャストすることができます。ハンディ!
IntPtr hierarchyPointer, selectionContainerPointer;
Object selectedObject = null;
IVsMultiItemSelect multiItemSelect;
uint projectItemId;
IVsMonitorSelection monitorSelection =
(IVsMonitorSelection)Package.GetGlobalService(
typeof(SVsShellMonitorSelection));
monitorSelection.GetCurrentSelection(out hierarchyPointer,
out projectItemId,
out multiItemSelect,
out selectionContainerPointer);
IVsHierarchy selectedHierarchy = Marshal.GetTypedObjectForIUnknown(
hierarchyPointer,
typeof(IVsHierarchy)) as IVsHierarchy;
if (selectedHierarchy != null)
{
ErrorHandler.ThrowOnFailure(selectedHierarchy.GetProperty(
projectItemId,
(int)__VSHPROPID.VSHPROPID_ExtObject,
out selectedObject));
}
Project selectedProject = selectedObject as Project;
Here's the source
私はこれを見つけたので、満足している、これを行う方法をどこか他の所に見つけることができませんでした。 :D – bio595
私はMarshal.Release(hierarchyPtr)が不足していると思います。 Marshal.Release(selectionContainerPointer); 'を呼び出し、メモリリークを回避します。そうでなければ素晴らしい! – MickyD
これは明らかかもしれませんが、IntPtrの初心者ユーザとして、nullポインタの例外を避けるためにMarshal.Releaseを呼び出す前にselectionContainerPointer == IntPtr.Zeroをチェックできることを指摘する価値があります。 – webjprgm