예제 #1
0
        /// <summary>
        /// Convert a boxed primitive (generally of the backing type of an enum) into a ulong.
        /// </summary>
        protected static ulong ConvertEnumUnderlyingTypeToUInt64(object value, TypeCode typeCode)
        {
            Debug.Assert(value != null);

            unchecked
            {
                switch (typeCode)
                {
                case TypeCode.SByte:
                    return((ulong)(sbyte)value);

                case TypeCode.Int16:
                    return((ulong)(short)value);

                case TypeCode.Int32:
                    return((ulong)(int)value);

                case TypeCode.Int64:
                    return((ulong)(long)value);

                case TypeCode.Byte:
                    return((byte)value);

                case TypeCode.UInt16:
                    return((ushort)value);

                case TypeCode.UInt32:
                    return((uint)value);

                case TypeCode.UInt64:
                    return((ulong)value);

                default:
                    throw ExceptionUtilities.UnexpectedValue(typeCode);
                }
            }
        }
        /// <summary>
        /// Convert a boxed primitive (generally of the backing type of an enum) into a ulong.
        /// </summary>
        protected static ulong ConvertEnumUnderlyingTypeToUInt64(object value, TypeCode typeCode)
        {
            Debug.Assert(value != null);

            unchecked
            {
                switch (typeCode)
                {
                    case TypeCode.SByte:
                        return (ulong)(sbyte)value;
                    case TypeCode.Int16:
                        return (ulong)(short)value;
                    case TypeCode.Int32:
                        return (ulong)(int)value;
                    case TypeCode.Int64:
                        return (ulong)(long)value;
                    case TypeCode.Byte:
                        return (byte)value;
                    case TypeCode.UInt16:
                        return (ushort)value;
                    case TypeCode.UInt32:
                        return (uint)value;
                    case TypeCode.UInt64:
                        return (ulong)value;
                    default:
                        throw ExceptionUtilities.UnexpectedValue(typeCode);
                }
            }
        }