EnumValueTools
EnumValueTools
package haxe
import haxe.EnumTools
Available on all platformsThis class provides advanced methods on enum values. It is ideally used with
using EnumValueTools
and then acts as an extension to theEnumValue
types.If the first argument to any of the methods is null, the result is unspecified.
Static methods
static inline equals<T> (a:T, b:T ):Bool
Recursively compares two enum instances a
and b
by value.
Unlike a == b
, this function performs a deep equality check on the arguments of the constructors (if there are any).
If a
or b
are null
, the result is unspecified.
static inline getIndex (e:EnumValue):Int
Returns the index of enum instance e
.
This corresponds to the original syntactic position of e
. The index of the first declared constructor is 0, the next one is 1 etc.
If e
is null
, the result is unspecified.
static inline getName (e:EnumValue):String
Returns the constructor name of enum instance e
.
The result String does not contain any constructor arguments.
If e
is null
, the result is unspecified.
static inline getParameters (e:EnumValue):Array<Dynamic>
Returns a list of the constructor arguments of enum instance e
.
If e
has no arguments, the result is []
.
Otherwise the result are the values that were used as arguments to e
, in the order of their declaration.
If e
is null
, the result is unspecified.
static match (e:EnumValue, pattern:Dynamic):Bool
Matches enum instance e
against pattern pattern
, returning true
if matching succeeded and false
otherwise.
Example usage:
if (e.match(pattern)) {
// codeIfTrue
} else {
// codeIfFalse
}
This is equivalent to the following code:
switch (e) {
case pattern:
// codeIfTrue
case _:
// codeIfFalse
}
This method is implemented in the compiler. This definition exists only for documentation.
© 2005–2016 Haxe Foundation
Licensed under a MIT license.
http://api.haxe.org/haxe/EnumValueTools.html