コード例 #1
0
        private static void SelectBetween(this ISelectionService selectionService, 
            ISelectable[] siblings,
            ISelectable start,
            ISelectable end)
        {
            //Select nothing
            selectionService.SelectNone();

            //Determine the start and stop
            var startIndex = siblings.IndexOf(s => s == start);
            var endIndex = siblings.IndexOf(s => s == end);

            //If for some reason the siblings weren't found, bail
            if (startIndex == null || endIndex == null)
                return;

            //Always start from the "first" sibling
            var effectiveStart = Math.Min(startIndex.Value, endIndex.Value);
            var effectiveEnd = Math.Max(startIndex.Value, endIndex.Value);

            //Mark them all as selected.
            for (int index = effectiveStart; index <= effectiveEnd; index++)
            {
                selectionService.Select(siblings[index]);
            }
        }