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