本文整理汇总了C#中VSITEMSELECTION.Where方法的典型用法代码示例。如果您正苦于以下问题:C# VSITEMSELECTION.Where方法的具体用法?C# VSITEMSELECTION.Where怎么用?C# VSITEMSELECTION.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VSITEMSELECTION
的用法示例。
在下文中一共展示了VSITEMSELECTION.Where方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSelection
public IEnumerable<IVsHierarchyItem> GetSelection ()
{
return asyncManager.Run (async () => {
await asyncManager.SwitchToMainThread ();
var selHier = IntPtr.Zero;
uint selId;
IVsMultiItemSelect selMulti;
try {
ErrorHandler.ThrowOnFailure (hierarchyWindow.GetCurrentSelection (out selHier, out selId, out selMulti));
// There may be no selection at all.
if (selMulti == null && selHier == IntPtr.Zero)
return Enumerable.Empty<IVsHierarchyItem> ();
// This is a single item selection.
if (selMulti == null) {
return new[] { hierarchyManager.GetHierarchyItem (
(IVsHierarchy)Marshal.GetTypedObjectForIUnknown (selHier, typeof (IVsHierarchy)), selId) };
}
// This is a multiple item selection.
uint selCount;
int singleHier;
ErrorHandler.ThrowOnFailure (selMulti.GetSelectionInfo (out selCount, out singleHier));
var selection = new VSITEMSELECTION[selCount];
ErrorHandler.ThrowOnFailure (selMulti.GetSelectedItems (0, selCount, selection));
return selection.Where (sel => sel.pHier != null)
.Select (sel => hierarchyManager.GetHierarchyItem (sel.pHier, sel.itemid))
.ToArray ();
} finally {
if (selHier != IntPtr.Zero)
Marshal.Release (selHier);
}
});
}
示例2: GetSelection
public static IEnumerable<Tuple<IVsHierarchy, uint>> GetSelection(this IVsMonitorSelection monitorSelection, IUIThread uiThread, IVsHierarchy solution)
{
var hierarchyPtr = IntPtr.Zero;
var selectionContainer = IntPtr.Zero;
return uiThread.Invoke(() =>
{
try
{
// Get the current project hierarchy, project item, and selection container for the current selection
// If the selection spans multiple hierarchies, hierarchyPtr is Zero
uint itemid;
IVsMultiItemSelect multiItemSelect = null;
ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer));
if (itemid == VSConstants.VSITEMID_NIL)
return Enumerable.Empty<Tuple<IVsHierarchy, uint>>();
if (itemid == VSConstants.VSITEMID_ROOT)
{
if (hierarchyPtr == IntPtr.Zero)
return new[] { Tuple.Create(solution, VSConstants.VSITEMID_ROOT) };
else
return new[] { Tuple.Create(
(IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)),
VSConstants.VSITEMID_ROOT) };
}
if (itemid != VSConstants.VSITEMID_SELECTION)
return new[] { Tuple.Create(
(IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)),
itemid) };
// This is a multiple item selection.
uint numberOfSelectedItems;
int isSingleHierarchyInt;
ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
var isSingleHierarchy = (isSingleHierarchyInt != 0);
var vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
var flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0;
ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections));
return vsItemSelections.Where(sel => sel.pHier != null)
// NOTE: we can return lazy results here, since
// the GetSelectedItems has already returned in the UI thread
// the array of results. We're just delaying the creation of the tuples
// in case they aren't all needed.
.Select(sel => Tuple.Create(sel.pHier, sel.itemid));
}
finally
{
if (hierarchyPtr != IntPtr.Zero)
{
Marshal.Release(hierarchyPtr);
}
if (selectionContainer != IntPtr.Zero)
{
Marshal.Release(selectionContainer);
}
}
});
}
示例3: GetSelection
public IEnumerable<HierarchyItemPair> GetSelection ()
{
return asyncManager.Run (async () => {
// The VS selection operations must be performed on the UI thread.
await asyncManager.SwitchToMainThread ();
var selHier = IntPtr.Zero;
var selContainer = IntPtr.Zero;
uint selId;
IVsMultiItemSelect selMulti;
try {
// Get the current project hierarchy, project item, and selection container for the current selection
// If the selection spans multiple hierarchies, hierarchyPtr is Zero
ErrorHandler.ThrowOnFailure (monitorSelection.GetCurrentSelection (out selHier, out selId, out selMulti, out selContainer));
// There may be no selection at all.
if (selMulti == null && selHier == IntPtr.Zero)
return Enumerable.Empty<HierarchyItemPair> ();
// This is a single item selection.
if (selMulti == null) {
return new[] { new HierarchyItemPair (
(IVsHierarchy)Marshal.GetTypedObjectForIUnknown (selHier, typeof (IVsHierarchy)), selId) };
}
// This is a multiple item selection.
uint selCount;
int singleHier;
ErrorHandler.ThrowOnFailure (selMulti.GetSelectionInfo (out selCount, out singleHier));
var selection = new VSITEMSELECTION[selCount];
ErrorHandler.ThrowOnFailure (selMulti.GetSelectedItems (0, selCount, selection));
return selection.Where (sel => sel.pHier != null)
.Select (sel => new HierarchyItemPair (sel.pHier, sel.itemid))
.ToArray ();
} finally {
if (selHier != IntPtr.Zero) {
Marshal.Release (selHier);
}
if (selContainer != IntPtr.Zero) {
Marshal.Release (selContainer);
}
}
});
}