public static string Format(System.Type enumType, object value, string format) { ThrowHelper.ThrowIfNull(enumType); if (!enumType.IsEnum) { throw new System.ArgumentException(); } ThrowHelper.ThrowIfNull(value, format); if (enumType is RuntimeType enumRuntimeType) { var enumUnderlyingType = GetUnderlyingType(enumType); var enumCls = enumRuntimeType.JavaClassForArray(); var valueType = value.GetType(); if (value is Enum valueEnum) { var valueUnderlyingType = GetUnderlyingType(valueType); if (object.ReferenceEquals(enumUnderlyingType, valueUnderlyingType)) { return(Format(format, valueEnum.GetLong(), enumCls)); } } else if (object.ReferenceEquals(enumUnderlyingType, valueType)) { switch (value) { case byte byteValue: return(Format(format, (long)byteValue, enumCls)); case char charValue: return(Format(format, (long)charValue, enumCls)); case short shortValue: return(Format(format, (long)shortValue, enumCls)); case int intValue: return(Format(format, (long)intValue, enumCls)); case long longValue: return(Format(format, longValue, enumCls)); } } } throw new System.ArgumentException(); }
public static System.Array GetValues(System.Type enumType) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumValues()); }
public static string[] GetNames(System.Type enumType) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumNames()); }
public static string GetName(System.Type enumType, object value) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumName(value)); }
public static bool IsDefined(System.Type enumType, object value) { ThrowHelper.ThrowIfNull(enumType); return(enumType.IsEnumDefined(value)); }
// // implemented via System.Type: GetUnderlyingType, GetTypeCode, // IsDefined, GetName, GetNames, GetValues // public static System.Type GetUnderlyingType(System.Type enumType) { ThrowHelper.ThrowIfNull(enumType); return(enumType.GetEnumUnderlyingType()); }