Just use Enum.GetUnderlyingType
instead:
Returns the underlying type of the specified enumeration.
Here's the implementation for GetEnumUnderlyingType
from Type
:
public virtual Type GetEnumUnderlyingType()
{
if (!this.IsEnum)
throw new ArgumentException(
Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
FieldInfo[] fields = this.GetFields(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (fields == null || fields.Length != 1)
throw new ArgumentException(
Environment.GetResourceString("Argument_InvalidEnum"), "enumType");
return fields[0].FieldType;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.