src/Misc/EFTools/XmlCore/UI/Selection.cs
/// <summary>
///     Selection helper method.  This takes the existing selection in the
///     context and selects an item into it.  If the item is already in the
///     selection the selection is preserved and the item is promoted
///     to the primary selection.
/// </summary>
/// <param name="context">The editing context to apply this selection change to.</param>
/// <param name="itemToSelect">The item to select.</param>
/// <returns>A Selection object that contains the new selection.</returns>
/// <exception cref="ArgumentNullException">If context or itemToSelect is null.</exception>
Selection helper method.  This takes the existing selection in the
context and selects an item into it.  If the item is already in the
selection the selection is preserved and the item is promoted
to the primary selection.
Selection helper method . This takes the existing selection in the context and selects an item into it . If the item is already in the selection the selection is preserved and the item is promoted to the primary selection .
internal static T Select<T>(EditingContext context, EFObject itemToSelect) where T : Selection
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (itemToSelect == null)
            {
                throw new ArgumentNullException("itemToSelect");
            }
            var existing = context.Items.GetValue<T>();
            if (existing.PrimarySelection == itemToSelect)
            {
                return existing;
            }
            T selection = null;
            foreach (var obj in existing.SelectedObjects)
            {
                if (obj == itemToSelect)
                {
                    var list = new List<EFObject>(existing.SelectedObjects);
                    list.Remove(itemToSelect);
                    list.Insert(0, itemToSelect);
                    selection = Activator.CreateInstance<T>();
                    selection.SetSelectedObjects(list);
                }
            }
            if (selection == null)
            {
                selection = Activator.CreateInstance<T>();
                selection.SetSelectedObjects(itemToSelect);
            }
            context.Items.SetValue(selection);
            return selection;
        }
internal static T Select < T > ( EditingContext context , EFObject itemToSelect ) where T : Selection { if ( context == null ) { throw new ArgumentNullException ( " " ) ; } if ( itemToSelect == null ) { throw new ArgumentNullException ( " " ) ; } var existing = context . Items . GetValue < T > ( ) ; if ( existing . PrimarySelection == itemToSelect ) { return existing ; } T selection = null ; foreach ( var obj in existing . SelectedObjects ) { if ( obj == itemToSelect ) { var list = new List < EFObject > ( existing . SelectedObjects ) ; list . Remove ( itemToSelect ) ; list . Insert ( 0 , itemToSelect ) ; selection = Activator . CreateInstance < T > ( ) ; selection . SetSelectedObjects ( list ) ; } } if ( selection == null ) { selection = Activator . CreateInstance < T > ( ) ; selection . SetSelectedObjects ( itemToSelect ) ; } context . Items . SetValue ( selection ) ; return selection ; }
Selection helper method.
Selection helper method .
// short cut if we're already in the right state.
A Selection object that contains the new selection.
A Selection object that contains the new selection .
If context or itemToSelect is null.
If context or itemToSelect is null .
context
EditingContext
The editing context to apply this selection change to.
The editing context to apply this selection change to .
itemToSelect
EFObject
The item to select.
The item to select .