Skip to content

Enumeration Extensions

Adrian Gabor edited this page Nov 30, 2021 · 2 revisions

ToListExt

Description
Converts an instance of an enum into a List of strings.
Uses Linq which may affect time complexity.

Parameters
None

Usage

private enum ABC { A = 0, B = 1, C = 2 }

 ABC abc = new ABC();
string list = abc.ToListExt();

Outputs "A,B,C".


GetNameExt

Description
Gets the name of the enumeration constant with the value of the paramater.
Maps to Enum.GetName

Parameters
value (object)

Usage

private enum ABC { A = 0, B = 1, C = 2 }

 ABC abc = new ABC();
string name = abc.GetNameExt(2);

Outputs "C".


GetNamesExt

Description
Returns a string array of the names of an enum that matches the type of the emumeration being extended.
Maps to Enum.GetNames

Parameters
None

Usage

private enum ABC { A = 0, B = 1, C = 2 }

 ABC abc = new ABC();
string[] names = abc.GetNamesExt();

Outputs { "A", "B", "C" }.


ToStringExt

Description
Joins all values in an enumeration into a comma delimited string.

Parameters
None

Usage

private enum ABC { A = 0, B = 1, C = 2 }

 ABC abc = new ABC();
string enumString = abc.ToStringExt();

Outputs "A, B, C".

Clone this wiki locally