コード例 #1
0
        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();
        }
コード例 #2
0
 public static System.Array GetValues(System.Type enumType)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.GetEnumValues());
 }
コード例 #3
0
 public static string[] GetNames(System.Type enumType)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.GetEnumNames());
 }
コード例 #4
0
 public static string GetName(System.Type enumType, object value)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.GetEnumName(value));
 }
コード例 #5
0
 public static bool IsDefined(System.Type enumType, object value)
 {
     ThrowHelper.ThrowIfNull(enumType);
     return(enumType.IsEnumDefined(value));
 }
コード例 #6
0
        //
        // implemented via System.Type:  GetUnderlyingType, GetTypeCode,
        // IsDefined, GetName, GetNames, GetValues
        //

        public static System.Type GetUnderlyingType(System.Type enumType)
        {
            ThrowHelper.ThrowIfNull(enumType);
            return(enumType.GetEnumUnderlyingType());
        }