BGC Tools
Static Public Member Functions
BGC.Utility.EnumUtility Class Reference

Static Public Member Functions

static List< T > ToList< T > (bool ignoreMax=true)
 Convert enumerations to a list, optionally excluding any named "max" in lower case More...
 
static IEnumerable< T > ToEnumerable< T > (bool ignoreMax=true)
 Coroutine to return enum types More...
 
static JsonObject ToJsonObject< T > (string prependString="", bool ignoreMax=true)
 Convert Enum to JsonObject. More...
 

Detailed Description

Definition at line 8 of file EnumUtility.cs.

Member Function Documentation

◆ ToEnumerable< T >()

static IEnumerable<T> BGC.Utility.EnumUtility.ToEnumerable< T > ( bool  ignoreMax = true)
inlinestatic

Coroutine to return enum types

Definition at line 27 of file EnumUtility.cs.

28  {
29  foreach (T t in Enum.GetValues(typeof(T)))
30  {
31  if (ignoreMax == true && t.ToString().ToLowerInvariant().Equals("max") == false)
32  {
33  yield return t;
34  }
35  }
36  }

◆ ToJsonObject< T >()

static JsonObject BGC.Utility.EnumUtility.ToJsonObject< T > ( string  prependString = "",
bool  ignoreMax = true 
)
inlinestatic

Convert Enum to JsonObject.

Parameters
prependStringSet this if you want there be a value before every key
ignoreMaxSet this to true to not add any key that is max

Definition at line 41 of file EnumUtility.cs.

References LightJson.JsonObject.Add(), and LightJson.Array.

42  {
43  Assert.IsNotNull(prependString);
44 
45  JsonObject jo = new JsonObject();
46  Array enumValues = Enum.GetValues(typeof(T));
47 
48  int length = enumValues.Length;
49  for(int i = 0; i < length; ++i)
50  {
51  T t = (T) enumValues.GetValue(i);
52  string tName = t.ToString();
53 
54  if (ignoreMax == true && tName.ToLowerInvariant().Equals("max"))
55  {
56  continue;
57  }
58 
59  jo.Add($"{prependString}{((int)(object)t).ToString()}", tName);
60  }
61 
62  return jo;
63  }
Represents a key-value pair collection of JsonValue objects.
Definition: JsonObject.cs:13
JsonObject Add(string key)
Adds a key with a null value to this collection.
Here is the call graph for this function:

◆ ToList< T >()

static List<T> BGC.Utility.EnumUtility.ToList< T > ( bool  ignoreMax = true)
inlinestatic

Convert enumerations to a list, optionally excluding any named "max" in lower case

Definition at line 11 of file EnumUtility.cs.

12  {
13  List<T> list = new List<T>();
14 
15  foreach (T t in Enum.GetValues(typeof(T)))
16  {
17  if (ignoreMax == true && t.ToString().ToLowerInvariant().Equals("max") == false)
18  {
19  list.Add(t);
20  }
21  }
22 
23  return list;
24  }

The documentation for this class was generated from the following file: