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 toggled
///     state of the item.  If the item is to be
///     added to the selection, it is added as the primary selection.
/// </summary>
/// <param name="context">The editing context to apply this selection change to.</param>
/// <param name="itemToToggle">The item to toggle selection for.</param>
/// <returns>A Selection object that contains the new selection.</returns>
/// <exception cref="ArgumentNullException">If context or itemToToggle is null.</exception>
Selection helper method.  This takes the existing selection in the
context and creates a new selection that contains the toggled
state of the item.  If the item is to be
added to the selection, it is added as the primary selection.
Selection helper method . This takes the existing selection in the context and creates a new selection that contains the toggled state of the item . If the item is to be added to the selection it is added as the primary selection .
internal static T Toggle<T>(EditingContext context, EFObject itemToToggle) where T : Selection
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (itemToToggle == null)
            {
                throw new ArgumentNullException("itemToToggle");
            }
            var existing = context.Items.GetValue<T>();
            var list = new List<EFObject>(existing.SelectedObjects);
            if (list.Contains(itemToToggle))
            {
                list.Remove(itemToToggle);
            }
            else
            {
                list.Insert(0, itemToToggle);
            }
            var selection = Activator.CreateInstance<T>();
            selection.SetSelectedObjects(list);
            context.Items.SetValue(selection);
            return selection;
        }
internal static T Toggle < T > ( EditingContext context , EFObject itemToToggle ) where T : Selection { if ( context == null ) { throw new ArgumentNullException ( " " ) ; } if ( itemToToggle == null ) { throw new ArgumentNullException ( " " ) ; } var existing = context . Items . GetValue < T > ( ) ; var list = new List < EFObject > ( existing . SelectedObjects ) ; if ( list . Contains ( itemToToggle ) ) { list . Remove ( itemToToggle ) ; } else { list . Insert ( 0 , itemToToggle ) ; } var selection = Activator . CreateInstance < T > ( ) ; selection . SetSelectedObjects ( list ) ; context . Items . SetValue ( selection ) ; return selection ; }
Selection helper method.
Selection helper method .
// Is the item already in the selection?  If so, remove it. // If not, add it to the beginning.
A Selection object that contains the new selection.
A Selection object that contains the new selection .
If context or itemToToggle is null.
If context or itemToToggle is null .
context
EditingContext
The editing context to apply this selection change to.
The editing context to apply this selection change to .
itemToToggle
EFObject
The item to toggle selection for.
The item to toggle selection for .