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

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

Properties

AllValues

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

Average

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

Count

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

State

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

ValencePairs

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

Values

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

Indexers

this[]

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

Methods

AppendToMenu

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

Assign

#
Assign a new plurality.
public void Assign(
values
Value to parse.
)

Assign

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

Clear

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

Events

Changed

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