元编程参考文档

枚举操作

20 个节点

本页内容 20

添加标志

函数

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

签名
添加标志(值: TEnum, 标志: TEnum) -> TEnum
TEnum AddFlag(TEnum value, TEnum flag)

参数

名称类型默认值说明
值TEnum—The value to start from; a value below zero throws System.OverflowException.
标志TEnum—The flag or flags to add; a value below zero throws System.OverflowException.

返回

ResultTEnum
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

格式化

函数

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.

签名
格式化(值: TEnum, 格式: 文本) -> 文本
string Format(TEnum value, string format)

参数

名称类型默认值说明
值TEnum—The value to write.
格式文本—"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.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

由数值取枚举值

函数

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

签名
由数值取枚举值(值: 任意) -> TEnum
TEnum FromValue(object value)

参数

名称类型默认值说明
值任意—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.

返回

ResultTEnum

备注

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.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

获取枚举值

函数

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.

签名
获取枚举值(枚举类型: Type) -> 数组
Array GetEnumValues(Type enumType)

参数

名称类型默认值说明
枚举类型Type—The enum type to list; null throws System.ArgumentNullException and a type that is not an enum throws System.ArgumentException.

返回

结果数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

获取名称

函数

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).

签名
获取名称(值: TEnum) -> 文本
string GetName(TEnum value)

参数

名称类型默认值说明
值TEnum—The value to name.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

获取所有名称

函数

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

签名
获取所有名称() -> 文本数组
string[] GetNames()

返回

结果文本数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

获取基础类型

函数

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

签名
获取基础类型() -> Type
Type GetUnderlyingType()

返回

结果Type
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

获取值列表

函数

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

签名
获取值列表() -> IReadOnlyList<TEnum>
IReadOnlyList<TEnum> GetValueList()

返回

结果IReadOnlyList<TEnum>
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

获取所有值

函数

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

签名
获取所有值() -> TEnum 数组
TEnum[] GetValues()

返回

结果TEnum 数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

包含标志

函数

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).

签名
包含标志(值: TEnum, 标志: TEnum) -> 真否
bool HasFlag(TEnum value, TEnum flag)

参数

名称类型默认值说明
值TEnum—The combined value to test; a value below zero throws System.OverflowException.
标志TEnum—The flag or flags to look for; a zero flag is always present. A value below zero throws System.OverflowException.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

是否已定义

函数

重载 1/2

签名
是否已定义(值: TEnum) -> 真否
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.

参数

名称类型默认值说明
值TEnum—The value to check.

返回

结果真否

备注

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

重载 2/2

签名
是否已定义(名称: 文本) -> 真否
bool IsDefined(string name)

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

参数

名称类型默认值说明
名称文本—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.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

是否为零

函数

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

签名
是否为零(值: TEnum) -> 真否
bool IsZero(TEnum value)

参数

名称类型默认值说明
值TEnum—The value to test; a value below zero throws System.OverflowException.

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

解析枚举

函数

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

签名
解析枚举(文本: 文本, 忽略大小写: 真否) -> TEnum
TEnum Parse(string text, bool ignoreCase = true)

参数

名称类型默认值说明
文本文本—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.
忽略大小写真否TrueWhen true (the default), names match regardless of letter case.

返回

ResultTEnum

备注

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.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

移除标志

函数

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

签名
移除标志(值: TEnum, 标志: TEnum) -> TEnum
TEnum RemoveFlag(TEnum value, TEnum flag)

参数

名称类型默认值说明
值TEnum—The value to start from; a value below zero throws System.OverflowException.
标志TEnum—The flag or flags to remove; a value below zero throws System.OverflowException.

返回

ResultTEnum
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

切换标志

函数

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

签名
切换标志(值: TEnum, 标志: TEnum) -> TEnum
TEnum ToggleFlag(TEnum value, TEnum flag)

参数

名称类型默认值说明
值TEnum—The value to start from; a value below zero throws System.OverflowException.
标志TEnum—The flag or flags to flip; a value below zero throws System.OverflowException.

返回

ResultTEnum
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

尝试由已定义的数值取枚举值

函数

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.

签名
尝试由已定义的数值取枚举值(值: 任意) -> (结果: 真否, 结果: TEnum)
bool TryFromDefinedValue(object value, out TEnum result)

参数

名称类型默认值说明
值任意—The number to convert; may be null.

返回

结果真否
结果TEnum
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

尝试由数值取枚举值

函数

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.

签名
尝试由数值取枚举值(值: 任意) -> (结果: 真否, 结果: TEnum)
bool TryFromValue(object value, out TEnum result)

参数

名称类型默认值说明
值任意—The number to convert; may be null.

返回

结果真否
结果TEnum
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

尝试获取名称

函数

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.

签名
尝试获取名称(值: TEnum) -> 文本
string TryGetName(TEnum value)

参数

名称类型默认值说明
值TEnum—The value to name.

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

尝试解析枚举

函数

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.

签名
尝试解析枚举 -> (结果: 真否, 值: TEnum)
    文本: 文本
    忽略大小写: 真否
bool TryParse(
    string text,
    out TEnum value,
    bool ignoreCase = true)

参数

名称类型默认值说明
文本文本—The text to read; null, empty or unrecognised text answers false.
忽略大小写真否TrueWhen true (the default), names match regardless of letter case.

返回

结果真否
值TEnum
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库

尝试解析已定义的枚举

函数

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.

签名
尝试解析已定义的枚举 -> (结果: 真否, 值: TEnum)
    文本: 文本
    忽略大小写: 真否
bool TryParseDefined(
    string text,
    out TEnum value,
    bool ignoreCase = true)

参数

名称类型默认值说明
文本文本—The text to read; null, empty or unrecognised text answers false.
忽略大小写真否TrueWhen true (the default), names match regardless of letter case.

返回

结果真否
值TEnum
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
数据流 函数 事件 例程 蓝图 状态机状态
声明于
枚举操作
所属包
标准库