public static Instruction Create(Type type, bool liftedToNull) { // Boxed enums can be unboxed as their underlying types: Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType(); if (liftedToNull) { switch (underlyingType.GetTypeCode()) { case TypeCode.Boolean: return(s_BooleanLiftedToNull ?? (s_BooleanLiftedToNull = new EqualBooleanLiftedToNull())); case TypeCode.SByte: return(s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new EqualSByteLiftedToNull())); case TypeCode.Int16: return(s_Int16LiftedToNull ?? (s_Int16LiftedToNull = new EqualInt16LiftedToNull())); case TypeCode.Char: return(s_CharLiftedToNull ?? (s_CharLiftedToNull = new EqualCharLiftedToNull())); case TypeCode.Int32: return(s_Int32LiftedToNull ?? (s_Int32LiftedToNull = new EqualInt32LiftedToNull())); case TypeCode.Int64: return(s_Int64LiftedToNull ?? (s_Int64LiftedToNull = new EqualInt64LiftedToNull())); case TypeCode.Byte: return(s_ByteLiftedToNull ?? (s_ByteLiftedToNull = new EqualByteLiftedToNull())); case TypeCode.UInt16: return(s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new EqualUInt16LiftedToNull())); case TypeCode.UInt32: return(s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new EqualUInt32LiftedToNull())); case TypeCode.UInt64: return(s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new EqualUInt64LiftedToNull())); case TypeCode.Single: return(s_SingleLiftedToNull ?? (s_SingleLiftedToNull = new EqualSingleLiftedToNull())); default: Debug.Assert(underlyingType.GetTypeCode() == TypeCode.Double); return(s_DoubleLiftedToNull ?? (s_DoubleLiftedToNull = new EqualDoubleLiftedToNull())); } } else { switch (underlyingType.GetTypeCode()) { case TypeCode.Boolean: return(s_Boolean ?? (s_Boolean = new EqualBoolean())); case TypeCode.SByte: return(s_SByte ?? (s_SByte = new EqualSByte())); case TypeCode.Int16: return(s_Int16 ?? (s_Int16 = new EqualInt16())); case TypeCode.Char: return(s_Char ?? (s_Char = new EqualChar())); case TypeCode.Int32: return(s_Int32 ?? (s_Int32 = new EqualInt32())); case TypeCode.Int64: return(s_Int64 ?? (s_Int64 = new EqualInt64())); case TypeCode.Byte: return(s_Byte ?? (s_Byte = new EqualByte())); case TypeCode.UInt16: return(s_UInt16 ?? (s_UInt16 = new EqualUInt16())); case TypeCode.UInt32: return(s_UInt32 ?? (s_UInt32 = new EqualUInt32())); case TypeCode.UInt64: return(s_UInt64 ?? (s_UInt64 = new EqualUInt64())); case TypeCode.Single: return(s_Single ?? (s_Single = new EqualSingle())); case TypeCode.Double: return(s_Double ?? (s_Double = new EqualDouble())); default: // Nullable only valid if one operand is constant null, so this assert is slightly too broad. Debug.Assert(type.IsNullableOrReferenceType()); return(s_reference ?? (s_reference = new EqualReference())); } } }
public static Instruction Create(Type type, bool liftedToNull) { if (liftedToNull) { switch (type.GetNonNullable().GetTypeCode()) { case TypeCode.Boolean: return(_booleanLiftedToNull ?? (_booleanLiftedToNull = new EqualBooleanLiftedToNull())); case TypeCode.SByte: return(_sByteLiftedToNull ?? (_sByteLiftedToNull = new EqualSByteLiftedToNull())); case TypeCode.Int16: return(_int16LiftedToNull ?? (_int16LiftedToNull = new EqualInt16LiftedToNull())); case TypeCode.Char: return(_charLiftedToNull ?? (_charLiftedToNull = new EqualCharLiftedToNull())); case TypeCode.Int32: return(_int32LiftedToNull ?? (_int32LiftedToNull = new EqualInt32LiftedToNull())); case TypeCode.Int64: return(_int64LiftedToNull ?? (_int64LiftedToNull = new EqualInt64LiftedToNull())); case TypeCode.Byte: return(_byteLiftedToNull ?? (_byteLiftedToNull = new EqualByteLiftedToNull())); case TypeCode.UInt16: return(_uInt16LiftedToNull ?? (_uInt16LiftedToNull = new EqualUInt16LiftedToNull())); case TypeCode.UInt32: return(_uInt32LiftedToNull ?? (_uInt32LiftedToNull = new EqualUInt32LiftedToNull())); case TypeCode.UInt64: return(_uInt64LiftedToNull ?? (_uInt64LiftedToNull = new EqualUInt64LiftedToNull())); case TypeCode.Single: return(_singleLiftedToNull ?? (_singleLiftedToNull = new EqualSingleLiftedToNull())); default: Debug.Assert(type.GetNonNullable().GetTypeCode() == TypeCode.Double); return(_doubleLiftedToNull ?? (_doubleLiftedToNull = new EqualDoubleLiftedToNull())); } } switch (type.GetNonNullable().GetTypeCode()) { case TypeCode.Boolean: return(_boolean ?? (_boolean = new EqualBoolean())); case TypeCode.SByte: return(_sByte ?? (_sByte = new EqualSByte())); case TypeCode.Int16: return(_int16 ?? (_int16 = new EqualInt16())); case TypeCode.Char: return(_char ?? (_char = new EqualChar())); case TypeCode.Int32: return(_int32 ?? (_int32 = new EqualInt32())); case TypeCode.Int64: return(_int64 ?? (_int64 = new EqualInt64())); case TypeCode.Byte: return(_byte ?? (_byte = new EqualByte())); case TypeCode.UInt16: return(_uInt16 ?? (_uInt16 = new EqualUInt16())); case TypeCode.UInt32: return(_uInt32 ?? (_uInt32 = new EqualUInt32())); case TypeCode.UInt64: return(_uInt64 ?? (_uInt64 = new EqualUInt64())); case TypeCode.Single: return(_single ?? (_single = new EqualSingle())); case TypeCode.Double: return(_double ?? (_double = new EqualDouble())); default: // Nullable only valid if one operand is constant null, so this assert is slightly too broad. Debug.Assert(type.CanBeNull()); return(_reference ?? (_reference = new EqualReference())); } }
public static Instruction Create(Type type, bool liftedToNull) { // Boxed enums can be unboxed as their underlying types: if (liftedToNull) { switch (TypeHelper.GetTypeCode(type.IsEnum ? Enum.GetUnderlyingType(type) : TypeHelper.GetNonNullableType(type))) { case TypeCode.Boolean: return s_booleanLiftedToNull ?? (s_booleanLiftedToNull = new EqualBooleanLiftedToNull()); case TypeCode.SByte: return s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new EqualSByteLiftedToNull()); case TypeCode.Byte: return s_byteLiftedToNull ?? (s_byteLiftedToNull = new EqualByteLiftedToNull()); case TypeCode.Char: return s_charLiftedToNull ?? (s_charLiftedToNull = new EqualCharLiftedToNull()); case TypeCode.Int16: return s_int16LiftedToNull ?? (s_int16LiftedToNull = new EqualInt16LiftedToNull()); case TypeCode.Int32: return s_int32LiftedToNull ?? (s_int32LiftedToNull = new EqualInt32LiftedToNull()); case TypeCode.Int64: return s_int64LiftedToNull ?? (s_int64LiftedToNull = new EqualInt64LiftedToNull()); case TypeCode.UInt16: return s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new EqualUInt16LiftedToNull()); case TypeCode.UInt32: return s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new EqualUInt32LiftedToNull()); case TypeCode.UInt64: return s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new EqualUInt64LiftedToNull()); case TypeCode.Single: return s_singleLiftedToNull ?? (s_singleLiftedToNull = new EqualSingleLiftedToNull()); case TypeCode.Double: return s_doubleLiftedToNull ?? (s_doubleLiftedToNull = new EqualDoubleLiftedToNull()); case TypeCode.String: case TypeCode.Object: if (!type.IsValueType) { return s_referenceLiftedToNull ?? (s_referenceLiftedToNull = new EqualReferenceLiftedToNull()); } // TODO: Nullable<T> throw Error.ExpressionNotSupportedForNullableType("Equal", type); default: throw Error.ExpressionNotSupportedForType("Equal", type); } } else { switch (TypeHelper.GetTypeCode(type.IsEnum ? Enum.GetUnderlyingType(type) : TypeHelper.GetNonNullableType(type))) { case TypeCode.Boolean: return s_boolean ?? (s_boolean = new EqualBoolean()); case TypeCode.SByte: return s_SByte ?? (s_SByte = new EqualSByte()); case TypeCode.Byte: return s_byte ?? (s_byte = new EqualByte()); case TypeCode.Char: return s_char ?? (s_char = new EqualChar()); case TypeCode.Int16: return s_int16 ?? (s_int16 = new EqualInt16()); case TypeCode.Int32: return s_int32 ?? (s_int32 = new EqualInt32()); case TypeCode.Int64: return s_int64 ?? (s_int64 = new EqualInt64()); case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new EqualUInt16()); case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new EqualUInt32()); case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new EqualUInt64()); case TypeCode.Single: return s_single ?? (s_single = new EqualSingle()); case TypeCode.Double: return s_double ?? (s_double = new EqualDouble()); case TypeCode.String: case TypeCode.Object: if (!type.IsValueType) { return s_reference ?? (s_reference = new EqualReference()); } // TODO: Nullable<T> throw Error.ExpressionNotSupportedForNullableType("Equal", type); default: throw Error.ExpressionNotSupportedForType("Equal", type); } } }
public static Instruction Create(Type type, bool liftedToNull) { // Boxed enums can be unboxed as their underlying types: if (liftedToNull) { switch ((type.IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType()).GetTypeCode()) { case TypeCode.Boolean: return(_booleanLiftedToNull ?? (_booleanLiftedToNull = new EqualBooleanLiftedToNull())); case TypeCode.SByte: return(_sbyteLiftedToNull ?? (_sbyteLiftedToNull = new EqualSByteLiftedToNull())); case TypeCode.Byte: return(_byteLiftedToNull ?? (_byteLiftedToNull = new EqualByteLiftedToNull())); case TypeCode.Char: return(_charLiftedToNull ?? (_charLiftedToNull = new EqualCharLiftedToNull())); case TypeCode.Int16: return(_int16LiftedToNull ?? (_int16LiftedToNull = new EqualInt16LiftedToNull())); case TypeCode.Int32: return(_int32LiftedToNull ?? (_int32LiftedToNull = new EqualInt32LiftedToNull())); case TypeCode.Int64: return(_int64LiftedToNull ?? (_int64LiftedToNull = new EqualInt64LiftedToNull())); case TypeCode.UInt16: return(_uint16LiftedToNull ?? (_uint16LiftedToNull = new EqualUInt16LiftedToNull())); case TypeCode.UInt32: return(_uint32LiftedToNull ?? (_uint32LiftedToNull = new EqualUInt32LiftedToNull())); case TypeCode.UInt64: return(_uint64LiftedToNull ?? (_uint64LiftedToNull = new EqualUInt64LiftedToNull())); case TypeCode.Single: return(_singleLiftedToNull ?? (_singleLiftedToNull = new EqualSingleLiftedToNull())); case TypeCode.Double: return(_doubleLiftedToNull ?? (_doubleLiftedToNull = new EqualDoubleLiftedToNull())); case TypeCode.String: case TypeCode.Object: if (!type.IsValueType) { return(_referenceLiftedToNull ?? (_referenceLiftedToNull = new EqualReferenceLiftedToNull())); } // TODO: Nullable<T> throw Error.ExpressionNotSupportedForNullableType("Equal", type); default: throw Error.ExpressionNotSupportedForType("Equal", type); } } else { switch ((type.IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType()).GetTypeCode()) { case TypeCode.Boolean: return(_boolean ?? (_boolean = new EqualBoolean())); case TypeCode.SByte: return(_sbyte ?? (_sbyte = new EqualSByte())); case TypeCode.Byte: return(_byte ?? (_byte = new EqualByte())); case TypeCode.Char: return(_char ?? (_char = new EqualChar())); case TypeCode.Int16: return(_int16 ?? (_int16 = new EqualInt16())); case TypeCode.Int32: return(_int32 ?? (_int32 = new EqualInt32())); case TypeCode.Int64: return(_int64 ?? (_int64 = new EqualInt64())); case TypeCode.UInt16: return(_uint16 ?? (_uint16 = new EqualUInt16())); case TypeCode.UInt32: return(_uint32 ?? (_uint32 = new EqualUInt32())); case TypeCode.UInt64: return(_uint64 ?? (_uint64 = new EqualUInt64())); case TypeCode.Single: return(_single ?? (_single = new EqualSingle())); case TypeCode.Double: return(_double ?? (_double = new EqualDouble())); case TypeCode.String: case TypeCode.Object: if (!type.IsValueType) { return(_reference ?? (_reference = new EqualReference())); } // TODO: Nullable<T> throw Error.ExpressionNotSupportedForNullableType("Equal", type); default: throw Error.ExpressionNotSupportedForType("Equal", type); } } }
public static Instruction Create(Type type, bool liftedToNull) { // Boxed enums can be unboxed as their underlying types: Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType(); if (liftedToNull) { switch (underlyingType.GetTypeCode()) { case TypeCode.Boolean: return s_booleanLiftedToNull ?? (s_booleanLiftedToNull = new EqualBooleanLiftedToNull()); case TypeCode.SByte: return s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new EqualSByteLiftedToNull()); case TypeCode.Byte: return s_byteLiftedToNull ?? (s_byteLiftedToNull = new EqualByteLiftedToNull()); case TypeCode.Char: return s_charLiftedToNull ?? (s_charLiftedToNull = new EqualCharLiftedToNull()); case TypeCode.Int16: return s_int16LiftedToNull ?? (s_int16LiftedToNull = new EqualInt16LiftedToNull()); case TypeCode.Int32: return s_int32LiftedToNull ?? (s_int32LiftedToNull = new EqualInt32LiftedToNull()); case TypeCode.Int64: return s_int64LiftedToNull ?? (s_int64LiftedToNull = new EqualInt64LiftedToNull()); case TypeCode.UInt16: return s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new EqualUInt16LiftedToNull()); case TypeCode.UInt32: return s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new EqualUInt32LiftedToNull()); case TypeCode.UInt64: return s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new EqualUInt64LiftedToNull()); case TypeCode.Single: return s_singleLiftedToNull ?? (s_singleLiftedToNull = new EqualSingleLiftedToNull()); default: Debug.Assert(underlyingType.GetTypeCode() == TypeCode.Double); return s_doubleLiftedToNull ?? (s_doubleLiftedToNull = new EqualDoubleLiftedToNull()); } } else { switch (underlyingType.GetTypeCode()) { case TypeCode.Boolean: return s_boolean ?? (s_boolean = new EqualBoolean()); case TypeCode.SByte: return s_SByte ?? (s_SByte = new EqualSByte()); case TypeCode.Byte: return s_byte ?? (s_byte = new EqualByte()); case TypeCode.Char: return s_char ?? (s_char = new EqualChar()); case TypeCode.Int16: return s_int16 ?? (s_int16 = new EqualInt16()); case TypeCode.Int32: return s_int32 ?? (s_int32 = new EqualInt32()); case TypeCode.Int64: return s_int64 ?? (s_int64 = new EqualInt64()); case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new EqualUInt16()); case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new EqualUInt32()); case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new EqualUInt64()); case TypeCode.Single: return s_single ?? (s_single = new EqualSingle()); case TypeCode.Double: return s_double ?? (s_double = new EqualDouble()); default: // Nullable only valid if one operand is constant null, so this assert is slightly too broad. Debug.Assert(type.IsNullableOrReferenceType()); return s_reference ?? (s_reference = new EqualReference()); } } }