Version

ConvertEnum Method

Used to convert an object value to an enum of the specified type.
Syntax
'Declaration
 
Public Shared Function ConvertEnum( _
   ByVal value As Object, _
   ByVal defaultValue As Enum _
) As Enum
public static Enum ConvertEnum( 
   object value,
   Enum defaultValue
)

Parameters

value
Object to convert
defaultValue
Default value - the enum type is derived from the value and this value is when an invalid value is specified.

Return Value

The value converted to an enum of the same type as the default value or the default value itself is returned if the value is invalid for the specified enum type
Remarks
The value is verified to be a defined enum value for the specified enum type so this method should not be used where the enum type is a flagged enumeration since the IsDefined method of Enum will return false when a combined bit value is specified.
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also