Divooka Reference

Enum Routines

20 nodes

On this page 20

Add Flag

Function

Switches on the bits of Flag in Value; for a flag enum, adds that option. Options already on stay on.

Signature
AddFlag(value: TEnum, flag: TEnum) -> TEnum
TEnum AddFlag(TEnum value, TEnum flag)

Parameters

nametypedefaultdescription
valueTEnum—The value to start from; a value below zero throws System.OverflowException.
flagTEnum—The flag or flags to add; a value below zero throws System.OverflowException.

Returns

ResultTEnum
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Format

Function

Writes an enum value as text in a chosen style: its name, its number in decimal or hexadecimal, or its flags spelled out by name.

Signature
Format(value: TEnum, format: Text) -> Text
string Format(TEnum value, string format)

Parameters

nametypedefaultdescription
valueTEnum—The value to write.
formatText—"G" for the name (or the number when it has none), "D" for decimal, "X" for hexadecimal, "F" for a comma-separated list of flag names; letter case does not matter. Null, empty or white-space throws System.ArgumentException, and any other format throws System.FormatException.

Returns

resultText
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

From Value

Function

Turns a number into the enum value with that number, for example a value read from a file or a database column.

Signature
FromValue(value: Any) -> TEnum
TEnum FromValue(object value)

Parameters

nametypedefaultdescription
valueAny—The number to convert. Null throws System.ArgumentNullException; a value that cannot be converted throws System.InvalidCastException or System.FormatException; a number outside the underlying type's range throws System.OverflowException.

Returns

ResultTEnum

Remarks

The number is first converted to the enum's underlying integer type using invariant culture: text holding a number works, and a fractional number is rounded to the nearest whole number (halves to even). The result is not checked against the declared constants; use EnumRoutines.TryFromDefinedValue for that.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Get Enum Values

Function

Every value of an enum type chosen at run time, for when you only have the type as a value rather than as the node's type argument.

Signature
GetEnumValues(enumType: Type) -> Array
Array GetEnumValues(Type enumType)

Parameters

nametypedefaultdescription
enumTypeType—The enum type to list; null throws System.ArgumentNullException and a type that is not an enum throws System.ArgumentException.

Returns

resultArray
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Get Name

Function

The declared name of Value, or empty text when no constant has that exact value (for example a combination of flags without a name of its own).

Signature
GetName(value: TEnum) -> Text
string GetName(TEnum value)

Parameters

nametypedefaultdescription
valueTEnum—The value to name.

Returns

resultText
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Get Names

Function

The names of every constant the enum declares, for example to fill a drop-down list.

Signature
GetNames() -> Text Array
string[] GetNames()

Returns

resultText Array
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Get Underlying Type

Function

The integer type an enum stores its values in, which is System.Int32 unless the enum declares otherwise.

Signature
GetUnderlyingType() -> Type
Type GetUnderlyingType()

Returns

resultType
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Get Value List

Function

Every value the enum declares, as a read-only list; the same values in the same order as EnumRoutines.GetValues.

Signature
GetValueList() -> IReadOnlyList<TEnum>
IReadOnlyList<TEnum> GetValueList()

Returns

resultIReadOnlyList<TEnum>
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Get Values

Function

Every value the enum declares, for example to go through all the choices one by one.

Signature
GetValues() -> TEnum Array
TEnum[] GetValues()

Returns

resultTEnum Array
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Has Flag

Function

Whether every bit set in Flag is also set in Value; for a flag enum, whether the value includes that option (or all of several combined options).

Signature
HasFlag(value: TEnum, flag: TEnum) -> Truth
bool HasFlag(TEnum value, TEnum flag)

Parameters

nametypedefaultdescription
valueTEnum—The combined value to test; a value below zero throws System.OverflowException.
flagTEnum—The flag or flags to look for; a zero flag is always present. A value below zero throws System.OverflowException.

Returns

resultTruth
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Is Defined

Function

Overload 1 of 2

Signature
IsDefined(value: TEnum) -> Truth
bool IsDefined(TEnum value)

Whether Value is exactly one of the enum's named constants; use it to reject numbers that were cast or converted into the enum without matching any choice.

Parameters

nametypedefaultdescription
valueTEnum—The value to check.

Returns

resultTruth

Remarks

A combination of flags counts as defined only when the enum gives that combination its own name.

Overload 2 of 2

Signature
IsDefined(name: Text) -> Truth
bool IsDefined(string name)

Whether the enum declares a constant called Name, matched exactly and case-sensitively.

Parameters

nametypedefaultdescription
nameText—The name to look for; null, empty or white-space text answers false. A number in text form is not a name and answers false.

Returns

resultTruth
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Is Zero

Function

Whether Value has no bits set at all; for a flag enum, whether no option is chosen.

Signature
IsZero(value: TEnum) -> Truth
bool IsZero(TEnum value)

Parameters

nametypedefaultdescription
valueTEnum—The value to test; a value below zero throws System.OverflowException.

Returns

resultTruth
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Parse

Function

Turns text into an enum value, throwing when it cannot; use EnumRoutines.TryParse when the text may be bad.

Signature
Parse(text: Text, ignoreCase: Truth) -> TEnum
TEnum Parse(string text, bool ignoreCase = true)

Parameters

nametypedefaultdescription
textText—The text to read. Null throws System.ArgumentNullException; empty, white-space or unrecognised text throws System.ArgumentException; a number too large for the enum's underlying type throws System.OverflowException.
ignoreCaseTruthTrueWhen true (the default), names match regardless of letter case.

Returns

ResultTEnum

Remarks

The text may be a constant's name, a comma-separated list of names (combined as flags), or a number; a number is accepted even when no constant has that value, so check the result with EnumRoutines.IsDefined or use EnumRoutines.TryParseDefined if that matters.

Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Remove Flag

Function

Switches off the bits of Flag in Value; for a flag enum, removes that option. Options already off stay off.

Signature
RemoveFlag(value: TEnum, flag: TEnum) -> TEnum
TEnum RemoveFlag(TEnum value, TEnum flag)

Parameters

nametypedefaultdescription
valueTEnum—The value to start from; a value below zero throws System.OverflowException.
flagTEnum—The flag or flags to remove; a value below zero throws System.OverflowException.

Returns

ResultTEnum
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Toggle Flag

Function

Flips the bits of Flag in Value: options that were on go off and options that were off come on.

Signature
ToggleFlag(value: TEnum, flag: TEnum) -> TEnum
TEnum ToggleFlag(TEnum value, TEnum flag)

Parameters

nametypedefaultdescription
valueTEnum—The value to start from; a value below zero throws System.OverflowException.
flagTEnum—The flag or flags to flip; a value below zero throws System.OverflowException.

Returns

ResultTEnum
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Try From Defined Value

Function

Turns a number into the enum value with that number only if it is one of the enum's named constants; answers false for null, unconvertible or undeclared values instead of throwing.

Signature
TryFromDefinedValue(value: Any) -> (result: Truth, result: TEnum)
bool TryFromDefinedValue(object value, out TEnum result)

Parameters

nametypedefaultdescription
valueAny—The number to convert; may be null.

Returns

resultTruth
resultTEnum
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Try From Value

Function

Turns a number into the enum value with that number like EnumRoutines.FromValue, but answers false instead of throwing when the value is null or cannot be converted.

Signature
TryFromValue(value: Any) -> (result: Truth, result: TEnum)
bool TryFromValue(object value, out TEnum result)

Parameters

nametypedefaultdescription
valueAny—The number to convert; may be null.

Returns

resultTruth
resultTEnum
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Try Get Name

Function

The declared name of Value, or null when no constant has that exact value; unlike EnumRoutines.GetName, this lets you tell "no name" apart from a name.

Signature
TryGetName(value: TEnum) -> Text
string TryGetName(TEnum value)

Parameters

nametypedefaultdescription
valueTEnum—The value to name.

Returns

resultText
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Try Parse

Function

Turns text into an enum value without throwing, telling you whether it succeeded; it accepts the same text as EnumRoutines.Parse, including numbers that match no named constant.

Signature
TryParse -> (result: Truth, value: TEnum)
    text: Text
    ignoreCase: Truth
bool TryParse(
    string text,
    out TEnum value,
    bool ignoreCase = true)

Parameters

nametypedefaultdescription
textText—The text to read; null, empty or unrecognised text answers false.
ignoreCaseTruthTrueWhen true (the default), names match regardless of letter case.

Returns

resultTruth
valueTEnum
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library

Try Parse Defined

Function

Turns text into an enum value only if the result is one of the enum's named constants, so stray numbers and unnamed flag combinations are rejected; use it for validating user input.

Signature
TryParseDefined -> (result: Truth, value: TEnum)
    text: Text
    ignoreCase: Truth
bool TryParseDefined(
    string text,
    out TEnum value,
    bool ignoreCase = true)

Parameters

nametypedefaultdescription
textText—The text to read; null, empty or unrecognised text answers false.
ignoreCaseTruthTrueWhen true (the default), names match regardless of letter case.

Returns

resultTruth
valueTEnum
Ships with
Divooka ExploreDivooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Enum Routines
Package
Standard Library