System.Enum.GetName C# (CSharp) Method

GetName() private method

private GetName ( Type enumType, Object value ) : String
enumType Type
value Object
return String
        public static String GetName(Type enumType, Object value)
        {
            if (enumType == null)
                throw new ArgumentNullException("enumType");

            if (!(enumType is RuntimeType))
                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeType"), "enumType");

            if (!enumType.IsEnum)
                throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");

            if (value == null)
                throw new ArgumentNullException("value");

            Type valueType = value.GetType();

            if (valueType.IsEnum || valueType == intType || valueType == typeof(short) || valueType == typeof(ushort) || valueType == typeof(byte) || valueType == typeof(sbyte) || valueType == typeof(uint) || valueType == typeof(long) || valueType == typeof(ulong))
                return InternalGetValueAsString(enumType, value);

            throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value");
        }
        

Usage Example

Esempio n. 1
0
 private static EnumAttribute GetAttribute(Enum enumConstant) {
     EnumAttribute attribute = Attribute.GetCustomAttribute(ForValue(enumConstant), typeof(EnumAttribute)) as EnumAttribute;
     if (attribute == null) {
         D.Warn(ErrorMessages.EnumNoAttribute.Inject(enumConstant.GetName(), typeof(EnumAttribute).Name));
     }
     return attribute;
 }
All Usage Examples Of System.Enum::GetName