Plurality<T>

References
public sealed class Plurality<T>
Represents a collection of values, some of which may be identical. This class is used for 'varies' UI to keep track of multiple states.
T

Constructors

Plurality

#
public Plurality(Func<T, T, bool> compare, Func<T[], T> average, Func<T, T> preprocess)
Create a new plurality with an equality comparer.
compare (Func<T, T, bool>)Equality comparer. If null, the default comparer will be used.
average (Func<T[], T>)Averaging delegate. May not be null.
preprocess (Func<T, T>)Value preprocessing method.

Properties

AllValues

#
public IEnumerable<T> AllValues { get; }
Enumerate over all values in this plurality, including repeats. Enumeration starts with the most common value.

Average

#
public T Average { get; }
Gets the average of this collection. This value makes no sense if Count = 0.

Count

#
public int Count { get; }
Gets the number of unique values.

State

#
public PluralityState State { get; }
Gets the state of the current plurality.

ValencePairs

#
public IEnumerable<(T value, int valence)> ValencePairs { get; }
Iterate over all values and valences, in order of high valence to low.

Values

#
public IEnumerable<T> Values { get; }
Enumerate over all unique values in this plurality. Enumeration starts with the most common value.

Indexers

this[]

#
public T this[int index] { get; }
Gets the value at the given index. The index must be between zero and Count.
index (int)Index of value.
Value at index.

Methods

AppendToMenu

#
public int AppendToMenu(MenuItemCollection menu, Func<T, bool> include = null, Func<T, string> format = null, Func<T, string> tooltip = null, Func<T, Bitmap> render = null)
Create a context menu for all unique values in this plurality.
menu (MenuItemCollection)Menu to populate.
include (Func<T, bool> = null)Inclusion delegate. If null, all values will be included.
format (Func<T, string> = null)Value formatting delegate. If null, default formatting will be used.
tooltip (Func<T, string> = null)Tooltip formatting delegate. If null, no tooltip will be included.
render (Func<T, Bitmap> = null)Menu item image delegate. If null, no image will be included.
Number of items added to menu.

Assign

#
public void Assign(IEnumerable<T> values)
Assign a new plurality.
values (IEnumerable<T>)Value to parse.

Assign

#
public void Assign(T value)
Assign a new singular value.
value (T)Value to assign.

Clear

#
public void Clear()
Clear all values. This is synonymous with calling Assign(null);

Events

Changed

#
public event EventHandler<PluralityEventArgs<T>> Changed
Raised whenever the state or contents of this plurality collection changes.