Skip to content

EditableGrouping

kobi2294 edited this page Apr 18, 2019 · 3 revisions

Editable Grouping class

Provides an editable implementation of the IGrouping<K, T> interface. This means you can set the key on the constructor (not changeable), and then add values.

Details

  • Use the Key property to read the key
  • Use the Count property to read the number of values
  • Use the Add and Remove Methods to add or remove values
  • Use the ContainesValue Method to check if the groupings contains a specific value
  • Use the RemoveWhere method to remove multiple elements according to provided predicate
  • Use the Reset method to replace the list of values with an alternative list

Extension methods

Use the ToEditableGrouping grouping to convert the following into EditableGrouping<K, T>:

  • IGrouping<K, T>
  • IEnumerable<T> - providing a key

Example

            var eg = new MvvmKit.EditableGrouping<int, string>(4);
            eg.Reset("Four", "Quattro", "Arba", "Vier");
            eg.Add("yottsu");

            Console.WriteLine($"There are {eg.Count} ways to say 4");
            Console.WriteLine(String.Join(", ", eg));

            eg.RemoveWhere(s => s.Length > 4);
            Console.WriteLine("But these are the short ones:");
            Console.WriteLine(String.Join(", ", eg));