Enum.ToObject 方法

定义

将指定的整数值转换为枚举成员。Converts a specified integer value to an enumeration member.

重载

ToObject(Type, Int16)

将指定的 16 位有符号整数转换为枚举成员。Converts the specified 16-bit signed integer to an enumeration member.

ToObject(Type, UInt64)

将指定的 64 位无符号整数值转换为枚举成员。Converts the specified 64-bit unsigned integer value to an enumeration member.

ToObject(Type, UInt32)

将指定的 32 位无符号整数值转换为枚举成员。Converts the specified 32-bit unsigned integer value to an enumeration member.

ToObject(Type, UInt16)

将指定的 16 位无符号整数值转换为枚举成员。Converts the specified 16-bit unsigned integer value to an enumeration member.

ToObject(Type, SByte)

将指定的 8 位有符号整数值转换为枚举成员。Converts the specified 8-bit signed integer value to an enumeration member.

ToObject(Type, Object)

将具有整数值的指定对象转换为枚举成员。Converts the specified object with an integer value to an enumeration member.

ToObject(Type, Int64)

将指定的 64 位有符号整数转换为枚举成员。Converts the specified 64-bit signed integer to an enumeration member.

ToObject(Type, Int32)

将指定的 32 位有符号整数转换为枚举成员。Converts the specified 32-bit signed integer to an enumeration member.

ToObject(Type, Byte)

将指定的 8 位无符号整数转换为枚举成员。Converts the specified 8-bit unsigned integer to an enumeration member.

ToObject(Type, Int16)

将指定的 16 位有符号整数转换为枚举成员。Converts the specified 16-bit signed integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, short value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, short value);
static member ToObject : Type * int16 -> obj
Public Shared Function ToObject (enumType As Type, value As Short) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
Int16

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, Int16) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, Int16) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, UInt64)

重要

此 API 不符合 CLS。

将指定的 64 位无符号整数值转换为枚举成员。Converts the specified 64-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt64 value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, ulong value);
static member ToObject : Type * uint64 -> obj
Public Shared Function ToObject (enumType As Type, value As ULong) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
UInt64

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, UInt64) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, UInt64) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, UInt32)

重要

此 API 不符合 CLS。

将指定的 32 位无符号整数值转换为枚举成员。Converts the specified 32-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt32 value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, uint value);
static member ToObject : Type * uint32 -> obj
Public Shared Function ToObject (enumType As Type, value As UInteger) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
UInt32

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, UInt32) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, UInt32) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, UInt16)

重要

此 API 不符合 CLS。

将指定的 16 位无符号整数值转换为枚举成员。Converts the specified 16-bit unsigned integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::UInt16 value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, ushort value);
static member ToObject : Type * uint16 -> obj
Public Shared Function ToObject (enumType As Type, value As UShort) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
UInt16

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, UInt16) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, UInt16) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, SByte)

重要

此 API 不符合 CLS。

将指定的 8 位有符号整数值转换为枚举成员。Converts the specified 8-bit signed integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::SByte value);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, sbyte value);
static member ToObject : Type * sbyte -> obj
Public Shared Function ToObject (enumType As Type, value As SByte) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
SByte

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, SByte) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, SByte) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, Object)

将具有整数值的指定对象转换为枚举成员。Converts the specified object with an integer value to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::Object ^ value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, object value);
static member ToObject : Type * obj -> obj
Public Shared Function ToObject (enumType As Type, value As Object) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
Object

要转换为枚举成员的值。The value convert to an enumeration member.

返回

值为 value 的枚举对象。An enumeration object whose value is value.

属性

异常

enumTypevaluenullenumType or value is null.

enumType 不是 EnumenumType is not an Enum.

-or- value 不是类型 SByteInt16Int32Int64ByteUInt16UInt32UInt64value is not type SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, or UInt64.

注解

ToObject(Type, Object) 方法将整数值 value 转换为 value基础值的枚举成员。The ToObject(Type, Object) method converts the integral value value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, Int64)

将指定的 64 位有符号整数转换为枚举成员。Converts the specified 64-bit signed integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, long value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, long value);
static member ToObject : Type * int64 -> obj
Public Shared Function ToObject (enumType As Type, value As Long) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
Int64

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, Int64) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, Int64) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, Int32)

将指定的 32 位有符号整数转换为枚举成员。Converts the specified 32-bit signed integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, int value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, int value);
static member ToObject : Type * int -> obj
Public Shared Function ToObject (enumType As Type, value As Integer) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
Int32

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, Int32) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, Int32) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

ToObject(Type, Byte)

将指定的 8 位无符号整数转换为枚举成员。Converts the specified 8-bit unsigned integer to an enumeration member.

public:
 static System::Object ^ ToObject(Type ^ enumType, System::Byte value);
[System.Runtime.InteropServices.ComVisible(true)]
public static object ToObject (Type enumType, byte value);
static member ToObject : Type * byte -> obj
Public Shared Function ToObject (enumType As Type, value As Byte) As Object

参数

enumType
Type

要返回的枚举类型。The enumeration type to return.

value
Byte

要转换为枚举成员的值。The value to convert to an enumeration member.

返回

设置为 value 的枚举实例。An instance of the enumeration set to value.

属性

异常

enumTypenullenumType is null.

enumType 不是 EnumenumType is not an Enum.

注解

ToObject(Type, Byte) 方法将 value 转换为 value基础值的枚举成员。The ToObject(Type, Byte) method converts value to an enumeration member whose underlying value is value. 请注意,即使值超出 enumType 成员的界限,转换也会成功。Note that the conversion succeeds even if value is outside the bounds of enumType members. 若要确保 valueenumType 枚举的有效基础值,请将其传递到 IsDefined 方法。To ensure that value is a valid underlying value of the enumType enumeration, pass it to the IsDefined method.

此转换方法返回 Object类型的值。This conversion method returns a value of type Object. 然后,可以转换该对象或将其转换为 enumType类型的对象。You can then cast it or convert it to an object of type enumType.

另请参阅

适用于