System.Enum.GetTypeCode C# (CSharp) Method

GetTypeCode() public method

public GetTypeCode ( ) : TypeCode
return TypeCode
        public TypeCode GetTypeCode()
        {
            Type enumType = this.GetType();
            Type underlyingType = GetUnderlyingType(enumType);

            if (underlyingType == typeof(Int32))
            {
                return TypeCode.Int32;
            }

            if (underlyingType == typeof(sbyte))
            {
                return TypeCode.SByte;
            }

            if (underlyingType == typeof(Int16))
            {
                return TypeCode.Int16;
            }

            if (underlyingType == typeof(Int64))
            {
                return TypeCode.Int64;
            }

            if (underlyingType == typeof(UInt32))
            {
                return TypeCode.UInt32;
            }

            if (underlyingType == typeof(byte))
            {
                return TypeCode.Byte;
            }

            if (underlyingType == typeof(UInt16))
            {
                return TypeCode.UInt16;
            }

            if (underlyingType == typeof(UInt64))
            {
                return TypeCode.UInt64;
            }

            BCLDebug.Assert(false, "Unknown underlying type.");
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
        }

Usage Example

Esempio n. 1
0
 public void Add(Enum e)
 {
     int val = (int)Convert.ChangeType(e, e.GetTypeCode());
     string t = e.GetType().Name;
     if (!enums.ContainsKey(t))
         enums.Add(t, new SortedList<int, int>());
     SortedList<int, int> values = enums[t];
     values.Add(val, ++uniqValue);
 }
All Usage Examples Of System.Enum::GetTypeCode