public static Instruction Create(Type type) { // Boxed enums can be unboxed as their underlying types: Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : TypeUtils.GetNonNullableType(type); switch (underlyingType.GetTypeCode()) { case TypeCode.SByte: return(s_SByte ?? (s_SByte = new OrSByte())); case TypeCode.Byte: return(s_byte ?? (s_byte = new OrByte())); case TypeCode.Int16: return(s_int16 ?? (s_int16 = new OrInt16())); case TypeCode.Int32: return(s_int32 ?? (s_int32 = new OrInt32())); case TypeCode.Int64: return(s_int64 ?? (s_int64 = new OrInt64())); case TypeCode.UInt16: return(s_UInt16 ?? (s_UInt16 = new OrUInt16())); case TypeCode.UInt32: return(s_UInt32 ?? (s_UInt32 = new OrUInt32())); case TypeCode.UInt64: return(s_UInt64 ?? (s_UInt64 = new OrUInt64())); case TypeCode.Boolean: return(s_bool ?? (s_bool = new OrBool())); default: throw Error.ExpressionNotSupportedForType("Or", type); } }
public static Instruction Create(Type type) { // Boxed enums can be unboxed as their underlying types: switch (System.Dynamic.Utils.TypeExtensions.GetTypeCode(type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : TypeUtils.GetNonNullableType(type))) { case TypeCode.SByte: return s_SByte ?? (s_SByte = new OrSByte()); case TypeCode.Byte: return s_byte ?? (s_byte = new OrByte()); case TypeCode.Int16: return s_int16 ?? (s_int16 = new OrInt16()); case TypeCode.Int32: return s_int32 ?? (s_int32 = new OrInt32()); case TypeCode.Int64: return s_int64 ?? (s_int64 = new OrInt64()); case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new OrUInt16()); case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new OrUInt32()); case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new OrUInt64()); case TypeCode.Boolean: return s_bool ?? (s_bool = new OrBool()); default: throw Error.ExpressionNotSupportedForType("Or", type); } }