Example #1
0
        /// <summary>Read a <typeparamref name="TEnum"/> value from a stream</summary>
        /// <param name="s">Stream to read from</param>
        /// <param name="value">Enum value read from the stream</param>
        /// <remarks>
        /// Uses <typeparamref name="TEnum"/>'s underlying <see cref="TypeCode"/> to
        /// decide how big of a numeric type to read from the stream.
        /// </remarks>
        public static void Read(IO.EndianReader s, out TEnum value)
        {
            Contract.Requires(s != null);

            ulong stream_value;

            switch (Reflection.EnumUtil <TEnum> .UnderlyingTypeCode)
            {
            case TypeCode.Byte:
            case TypeCode.SByte: stream_value = s.ReadByte();
                break;

            case TypeCode.Int16:
            case TypeCode.UInt16: stream_value = s.ReadUInt16();
                break;

            case TypeCode.Int32:
            case TypeCode.UInt32: stream_value = s.ReadUInt32();
                break;

            case TypeCode.Int64:
            case TypeCode.UInt64: stream_value = s.ReadUInt64();
                break;

            default:
                throw new Debug.UnreachableException();
            }

            value = Reflection.EnumValue <TEnum> .FromUInt64(stream_value);
        }
Example #2
0
 public static void Read(this IO.EndianReader s, out ulong value) => value = s.ReadUInt64();