Empeld
Empeld plugin documentation.
pluginbase.Helpers.Data.AnyEnum Class Reference

Object that can act as any enumeration More...

Inheritance diagram for pluginbase.Helpers.Data.AnyEnum:

Public Member Functions

 AnyEnum ()
 
ToEnum< T > ()
 Convert AnyEnum to a typed enumeration More...
 
ToOtherEnum< T > ()
 Convert AnyEnum to a typed enumeration, though not necessarily of the same type as the original type More...
 
bool Is (Enum other)
 Determines whether this instance is the same as other. More...
 
bool Equals (AnyEnum other)
 Determines whether the specified pluginbase.Helpers.Data.AnyEnum is equal to the current pluginbase.Helpers.Data.AnyEnum. More...
 
bool Equals (Enum other)
 Determines whether the specified System.Enum is equal to the current pluginbase.Helpers.Data.AnyEnum. More...
 
override bool Equals (object obj)
 Determines whether the specified System.Object is equal to the current pluginbase.Helpers.Data.AnyEnum. More...
 
override int GetHashCode ()
 Serves as a hash function for a pluginbase.Helpers.Data.AnyEnum object. More...
 
override string ToString ()
 Returns a System.String that represents the current pluginbase.Helpers.Data.AnyEnum. More...
 

Static Public Member Functions

static implicit operator AnyEnum (Enum @enum)
 Convert an enum to an AnyEnum instance More...
 
static implicit operator string (AnyEnum any)
 Convert an AnyEnum instance to a string More...
 
static operator AnyEnum (string str)
 Convert a string to an anyenum instance More...
 
static AnyEnum FromString (string str)
 Get an AnyEnum instance from a previous ToString More...
 
static AnyEnum Impersonate (Type type, string val)
 Impersonate an enumeration. Only null-check validation More...
 
static AnyEnum Impersonate (string typeName, string val)
 Impersonate an enumeration. Only null-check validation More...
 
static bool operator== (AnyEnum left, AnyEnum right)
 Checks if the left enum is equivilant to the right More...
 
static bool operator== (AnyEnum left, Enum right)
 Checks if the left enum is equivilant to the right More...
 
static bool operator== (Enum left, AnyEnum right)
 Checks if the left enum is equivilant to the right More...
 
static bool operator!= (AnyEnum left, AnyEnum right)
 Checks if the left enum is not equivilant to the right More...
 
static bool operator!= (AnyEnum left, Enum right)
 Checks if the left enum is not equivilant to the right More...
 
static bool operator!= (Enum left, AnyEnum right)
 Checks if the left enum is not equivilant to the right More...
 

Detailed Description

Object that can act as any enumeration

Attribute: TypeConverter(typeof(AnyEnumTypeConverter))

Constructor & Destructor Documentation

◆ AnyEnum()

pluginbase.Helpers.Data.AnyEnum.AnyEnum ( )
16  { }

Member Function Documentation

◆ Equals() [1/3]

bool pluginbase.Helpers.Data.AnyEnum.Equals ( AnyEnum  other)

Determines whether the specified pluginbase.Helpers.Data.AnyEnum is equal to the current pluginbase.Helpers.Data.AnyEnum.

Parameters
otherThe pluginbase.Helpers.Data.AnyEnum to compare with the current pluginbase.Helpers.Data.AnyEnum.
Returns
true if the specified pluginbase.Helpers.Data.AnyEnum is equal to the current pluginbase.Helpers.Data.AnyEnum; otherwise, false.
160  {
161  return other._type == this._type && other._value == this._value;
162  }

◆ Equals() [2/3]

bool pluginbase.Helpers.Data.AnyEnum.Equals ( Enum  other)

Determines whether the specified System.Enum is equal to the current pluginbase.Helpers.Data.AnyEnum.

Parameters
otherThe System.Enum to compare with the current pluginbase.Helpers.Data.AnyEnum.
Returns
true if the specified System.Enum is equal to the current pluginbase.Helpers.Data.AnyEnum; otherwise, false.
171  {
172  if (other == null)
173  return false;
174 
175  return other.GetType().Name == this._type && other.ToString() == this._value;
176  }

◆ Equals() [3/3]

override bool pluginbase.Helpers.Data.AnyEnum.Equals ( object  obj)

Determines whether the specified System.Object is equal to the current pluginbase.Helpers.Data.AnyEnum.

Parameters
objThe System.Object to compare with the current pluginbase.Helpers.Data.AnyEnum.
Returns
true if the specified System.Object is equal to the current pluginbase.Helpers.Data.AnyEnum; otherwise, false.
185  {
186  AnyEnum other = obj as AnyEnum;
187  if (other != null)
188  return this.Equals(other);
189 
190  Enum otherEnum = obj as Enum;
191  if (otherEnum != null)
192  return this.Equals(otherEnum);
193 
194  return false;
195  }
bool Equals(AnyEnum other)
Determines whether the specified pluginbase.Helpers.Data.AnyEnum is equal to the current pluginbase...
Definition: AnyEnum.cs:159
AnyEnum()
Definition: AnyEnum.cs:15

◆ FromString()

static AnyEnum pluginbase.Helpers.Data.AnyEnum.FromString ( string  str)
static

Get an AnyEnum instance from a previous ToString

Returns
The string.
Parameters
strString.
87  {
88  if (string.IsNullOrEmpty(str))
89  throw new ArgumentNullException("str");
90 
91  int last = str.LastIndexOf('#');
92 
93  if (last < 0)
94  throw new FormatException("Enum string formatted incorrectly");
95 
96 
97  string typeString = str.Substring(0, last);
98 
99  if (string.IsNullOrWhiteSpace(typeString))
100  throw new FormatException("Invalid enum type");
101 
102  string val = str.Substring(last + 1);
103 
104  if (string.IsNullOrWhiteSpace(val))
105  throw new FormatException("Invalid enum value");
106 
107  return new AnyEnum(typeString, val);
108  }
AnyEnum()
Definition: AnyEnum.cs:15

◆ GetHashCode()

override int pluginbase.Helpers.Data.AnyEnum.GetHashCode ( )

Serves as a hash function for a pluginbase.Helpers.Data.AnyEnum object.

Returns
A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.
251  {
252  return _type.GetHashCode() ^ _value.GetHashCode();
253  }

◆ Impersonate() [1/2]

static AnyEnum pluginbase.Helpers.Data.AnyEnum.Impersonate ( Type  type,
string  val 
)
static

Impersonate an enumeration. Only null-check validation

Parameters
typeType.
valValue.
116  {
117  if (!type.IsEnum)
118  throw new ArgumentException("Type not enum");
119  if (string.IsNullOrEmpty(val))
120  throw new ArgumentNullException("val");
121  return new AnyEnum(type.Name, val);
122  }
AnyEnum()
Definition: AnyEnum.cs:15

◆ Impersonate() [2/2]

static AnyEnum pluginbase.Helpers.Data.AnyEnum.Impersonate ( string  typeName,
string  val 
)
static

Impersonate an enumeration. Only null-check validation

Parameters
typeNameType full name.
valValue.
130  {
131  if (string.IsNullOrEmpty(typeName))
132  throw new ArgumentNullException("typeName");
133  if (string.IsNullOrEmpty(val))
134  throw new ArgumentNullException("val");
135  return new AnyEnum(typeName, val);
136  }
AnyEnum()
Definition: AnyEnum.cs:15

◆ Is()

bool pluginbase.Helpers.Data.AnyEnum.Is ( Enum  other)

Determines whether this instance is the same as other.

Returns
true if this instance is other; otherwise, false.
Parameters
otherOther.
149  {
150  return this.Equals(other);
151  }
bool Equals(AnyEnum other)
Determines whether the specified pluginbase.Helpers.Data.AnyEnum is equal to the current pluginbase...
Definition: AnyEnum.cs:159

◆ operator AnyEnum() [1/2]

static implicit pluginbase.Helpers.Data.AnyEnum.operator AnyEnum ( Enum @  enum)
static

Convert an enum to an AnyEnum instance

34  {
35  return new AnyEnum(@enum);
36  }
AnyEnum()
Definition: AnyEnum.cs:15

◆ operator AnyEnum() [2/2]

static pluginbase.Helpers.Data.AnyEnum.operator AnyEnum ( string  str)
explicitstatic

Convert a string to an anyenum instance

50  {
51  return AnyEnum.FromString(str);
52  }
AnyEnum()
Definition: AnyEnum.cs:15

◆ operator string()

static implicit pluginbase.Helpers.Data.AnyEnum.operator string ( AnyEnum  any)
static

Convert an AnyEnum instance to a string

42  {
43  return any.ToString();
44  }

◆ operator!=() [1/3]

static bool pluginbase.Helpers.Data.AnyEnum.operator!= ( AnyEnum  left,
AnyEnum  right 
)
static

Checks if the left enum is not equivilant to the right

225  {
226  return !left.Equals(right);
227  }

◆ operator!=() [2/3]

static bool pluginbase.Helpers.Data.AnyEnum.operator!= ( AnyEnum  left,
Enum  right 
)
static

Checks if the left enum is not equivilant to the right

233  {
234  return !left.Equals(right);
235  }

◆ operator!=() [3/3]

static bool pluginbase.Helpers.Data.AnyEnum.operator!= ( Enum  left,
AnyEnum  right 
)
static

Checks if the left enum is not equivilant to the right

241  {
242  return !right.Equals(left);
243  }

◆ operator==() [1/3]

static bool pluginbase.Helpers.Data.AnyEnum.operator== ( AnyEnum  left,
AnyEnum  right 
)
static

Checks if the left enum is equivilant to the right

201  {
202  return left.Equals(right);
203  }

◆ operator==() [2/3]

static bool pluginbase.Helpers.Data.AnyEnum.operator== ( AnyEnum  left,
Enum  right 
)
static

Checks if the left enum is equivilant to the right

209  {
210  return left.Equals(right);
211  }

◆ operator==() [3/3]

static bool pluginbase.Helpers.Data.AnyEnum.operator== ( Enum  left,
AnyEnum  right 
)
static

Checks if the left enum is equivilant to the right

217  {
218  return right.Equals(left);
219  }

◆ ToEnum< T >()

T pluginbase.Helpers.Data.AnyEnum.ToEnum< T > ( )

Convert AnyEnum to a typed enumeration

Returns
The enum.
Template Parameters
TThe enumeration type.
60  {
61  if (!typeof(T).IsEnum)
62  throw new ArgumentException("T must be of type Enum");
63  if (typeof(T).Name != this._type)
64  throw new InvalidCastException("T does not match internal type");
65  return (T)Enum.Parse(typeof(T), _value);
66  }

◆ ToOtherEnum< T >()

T pluginbase.Helpers.Data.AnyEnum.ToOtherEnum< T > ( )

Convert AnyEnum to a typed enumeration, though not necessarily of the same type as the original type

Returns
The other enum.
Template Parameters
TThe enumeration type.
75  {
76  if (!typeof(T).IsEnum)
77  throw new ArgumentException("T must be of type Enum");
78  return (T)Enum.Parse(typeof(T), _value);
79  }

◆ ToString()

override string pluginbase.Helpers.Data.AnyEnum.ToString ( )

Returns a System.String that represents the current pluginbase.Helpers.Data.AnyEnum.

Returns
A System.String that represents the current pluginbase.Helpers.Data.AnyEnum.
264  {
265  return string.Format("{0}#{1}", _type, _value);
266  }

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