TriEngine  v0.0.16
General-purpose engine in C#/OpenGL
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
TriDevs.TriEngine.Extensions.EnumerationExtensions Class Reference

Extensions for System.Enum. More...

Static Public Member Functions

static T Include< T > (this Enum value, T append)
 Includes an enumerated type and returns the new value. More...
 
static T Remove< T > (this Enum value, T remove)
 Removes an enumerated type and returns the new value. More...
 
static bool Has< T > (this Enum value, T check)
 Checks if an enumerated type contains a value. More...
 
static bool Missing< T > (this Enum obj, T value)
 Checks if an enumerated type is missing a value. More...
 

Detailed Description

Extensions for System.Enum.

Member Function Documentation

static bool TriDevs.TriEngine.Extensions.EnumerationExtensions.Has< T > ( this Enum  value,
check 
)
static

Checks if an enumerated type contains a value.

Template Parameters
TThe enum type.
Parameters
valueThe enum to check.
checkValue to check for.
Returns
True if the enum has the value(s), false otherwise.
148  {
149  Type type = value.GetType();
150 
151  //determine the values
152  var parsed = new _Value(check, type);
153  if (parsed.Signed.HasValue) //if (parsed.Signed is long)
154  {
155  return (Convert.ToInt64(value) & (long)parsed.Signed) == (long)parsed.Signed;
156  }
157  if (parsed.Unsigned.HasValue) //if (parsed.Unsigned is ulong)
158  {
159  return (Convert.ToUInt64(value) & (ulong)parsed.Unsigned) == (ulong)parsed.Unsigned;
160  }
161  return false;
162  }
static T TriDevs.TriEngine.Extensions.EnumerationExtensions.Include< T > ( this Enum  value,
append 
)
static

Includes an enumerated type and returns the new value.

Template Parameters
TThe enum type.
Parameters
valueThe enum to append to.
appendValue to append.
Returns
New enum T with the new values.
94  {
95  var type = value.GetType();
96 
97  //determine the values
98  object result = value;
99  var parsed = new _Value(append, type);
100  if (parsed.Signed.HasValue) //if (parsed.Signed is long)
101  {
102  result = Convert.ToInt64(value) | (long)parsed.Signed;
103  }
104  else if (parsed.Unsigned.HasValue) //else if (parsed.Unsigned is ulong)
105  {
106  result = Convert.ToUInt64(value) | (ulong)parsed.Unsigned;
107  }
108 
109  //return the final value
110  return (T)Enum.Parse(type, result.ToString());
111  }
static bool TriDevs.TriEngine.Extensions.EnumerationExtensions.Missing< T > ( this Enum  obj,
value 
)
static

Checks if an enumerated type is missing a value.

Template Parameters
TThe enum type.
Parameters
objThe enum to check.
valueValue to check for.
Returns
True if the enum is missing the value(s), false otherwise.
172  {
173  return !Has(obj, value);
174  }
static T TriDevs.TriEngine.Extensions.EnumerationExtensions.Remove< T > ( this Enum  value,
remove 
)
static

Removes an enumerated type and returns the new value.

Template Parameters
TThe enum type.
Parameters
valueThe enum to remove from.
removeValue to remove.
Returns
New enum T with the value(s) removed.
121  {
122  Type type = value.GetType();
123 
124  //determine the values
125  object result = value;
126  var parsed = new _Value(remove, type);
127  if (parsed.Signed.HasValue) //if (parsed.Signed is long)
128  {
129  result = Convert.ToInt64(value) & ~(long)parsed.Signed;
130  }
131  else if (parsed.Unsigned.HasValue) //else if (parsed.Unsigned is ulong)
132  {
133  result = Convert.ToUInt64(value) & ~(ulong)parsed.Unsigned;
134  }
135 
136  //return the final value
137  return (T)Enum.Parse(type, result.ToString());
138  }

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