コード例 #1
0
        static EnumBitStreamer()
        {
            var        generation_args = new MethodGenerationArgs();
            MethodInfo read_method_info, write_method_info, swap_method;

            #region Get read/write method info
            if (generation_args.UseUnderlyingType)
            {
                // Since we use a type-parameter hack to imply we want to use the underlying type
                // for the TStreamType, we have to use reflection to instantiate StreamType<>
                // using kUnderlyingType, which kStreamType is set to up above
                var stream_type_gen_class = typeof(StreamType <>);
                var stream_type_class     = stream_type_gen_class.MakeGenericType(generation_args.StreamType);
                read_method_info  = stream_type_class.GetField("kRead").GetValue(null) as MethodInfo;
                write_method_info = stream_type_class.GetField("kWrite").GetValue(null) as MethodInfo;
                swap_method       = stream_type_class.GetField("kBitSwap").GetValue(null) as MethodInfo;
            }
            else
            {
                // If we don't use the type-parameter hack and instead are explicitly given the
                // integer type, we can safely instantiate StreamType<> without reflection
                read_method_info  = StreamType <TStreamType> .kRead;
                write_method_info = StreamType <TStreamType> .kWrite;
                swap_method       = StreamType <TStreamType> .kBitSwap;
            }
            #endregion

            kRead  = GenerateReadMethod(generation_args, read_method_info, swap_method);
            kWrite = GenerateWriteMethod(generation_args, write_method_info, swap_method);

            Instance = new EnumBitStreamer <TEnum, TStreamType, TOptions>();
        }
コード例 #2
0
        public BitStream Stream <TEnum>(ref TEnum value, int bitCount, IEnumBitStreamer <TEnum> implementation)
            where TEnum : struct, IComparable, IFormattable, IConvertible
        {
            Contract.Requires(implementation != null);

            implementation.Stream(this, ref value, bitCount);

            return(this);
        }