public MethodGenerationArgs() { EnumType = typeof(TEnum); StreamType = typeof(TStreamType); UnderlyingType = Enum.GetUnderlyingType(EnumType); // Check if the user wants us to always use the underlying type UseUnderlyingType = StreamType == typeof(EnumBinaryStreamerUseUnderlyingType); if (UseUnderlyingType) { StreamType = UnderlyingType; } EnumUtils.AssertTypeIsEnum(EnumType); EnumUtils.AssertUnderlyingTypeIsSupported(EnumType, UnderlyingType); AssertStreamTypeIsValid(out StreamTypeIsSigned); UnderlyingTypeNeedsConversion = UnderlyingType != StreamType; Options = new TOptions(); if (Options.UseNoneSentinelEncoding) { if (StreamType == typeof(sbyte) || StreamType == typeof(byte)) { throw new ArgumentException( "{0}: UseNoneSentinelEncoding can't operate on (s)byte types (StreamType)", EnumType.FullName); } } #region Options.BitSwap if (Options.BitSwap) { if (StreamTypeIsSigned) { throw new ArgumentException( "{0}: Bit-swapping only makes sense on flags/unsigned types, but StreamType is signed", EnumType.FullName); } } else { if (Options.BitSwapGuardAgainstOneBit) { Debug.Trace.IO.TraceInformation("{0}'s {1} says we should guard against one bit cases, but not bitswap", EnumType.FullName, typeof(TOptions).FullName); } } #endregion }
public MethodGenerationArgs() { EnumType = typeof(TEnum); StreamType = typeof(TStreamType); UnderlyingType = Enum.GetUnderlyingType(EnumType); // Check if the user wants us to always use the underlying type UseUnderlyingType = StreamType == typeof(EnumBinaryStreamerUseUnderlyingType); if (UseUnderlyingType) { StreamType = UnderlyingType; } EnumUtils.AssertTypeIsEnum(EnumType); EnumUtils.AssertUnderlyingTypeIsSupported(EnumType, UnderlyingType); AssertStreamTypeIsValid(); UnderlyingTypeNeedsConversion = UnderlyingType != StreamType; }