Ejemplo n.º 1
0
        public static Instruction Create(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            switch ((type.IsEnum() ? Enum.GetUnderlyingType(type) : type).GetTypeCode()) {
                case TypeCode.Boolean: return _Boolean ?? (_Boolean = new NotEqualBoolean());
                case TypeCode.SByte: return _SByte ?? (_SByte = new NotEqualSByte());
                case TypeCode.Byte: return _Byte ?? (_Byte = new NotEqualByte());
                case TypeCode.Char: return _Char ?? (_Char = new NotEqualChar());
                case TypeCode.Int16: return _Int16 ?? (_Int16 = new NotEqualInt16());
                case TypeCode.Int32: return _Int32 ?? (_Int32 = new NotEqualInt32());
                case TypeCode.Int64: return _Int64 ?? (_Int64 = new NotEqualInt64());

                case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new NotEqualInt16());
                case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new NotEqualInt32());
                case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new NotEqualInt64());

                case TypeCode.Single: return _Single ?? (_Single = new NotEqualSingle());
                case TypeCode.Double: return _Double ?? (_Double = new NotEqualDouble());

                case TypeCode.Object:
                    if (!type.IsValueType()) {
                        return _Reference ?? (_Reference = new NotEqualReference());
                    }
                    // TODO: Nullable<T>
                    throw new NotImplementedException();

                default:
                    throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        public static Instruction Create(Type type)
        {
            var typeInfo = type.GetTypeInfo();
            // Boxed enums can be unboxed as their underlying types:
            var typeToUse = typeInfo.IsEnum ? Enum.GetUnderlyingType(type) : type;

            switch (typeToUse.GetTypeCode())
            {
            case TypeCode.Boolean: return(s_boolean ?? (s_boolean = new NotEqualBoolean()));

            case TypeCode.SByte: return(s_SByte ?? (s_SByte = new NotEqualSByte()));

            case TypeCode.Byte: return(s_byte ?? (s_byte = new NotEqualByte()));

            case TypeCode.Char: return(s_char ?? (s_char = new NotEqualChar()));

            case TypeCode.Int16: return(s_int16 ?? (s_int16 = new NotEqualInt16()));

            case TypeCode.Int32: return(s_int32 ?? (s_int32 = new NotEqualInt32()));

            case TypeCode.Int64: return(s_int64 ?? (s_int64 = new NotEqualInt64()));

            case TypeCode.UInt16: return(s_UInt16 ?? (s_UInt16 = new NotEqualInt16()));

            case TypeCode.UInt32: return(s_UInt32 ?? (s_UInt32 = new NotEqualInt32()));

            case TypeCode.UInt64: return(s_UInt64 ?? (s_UInt64 = new NotEqualInt64()));

            case TypeCode.Single: return(s_single ?? (s_single = new NotEqualSingle()));

            case TypeCode.Double: return(s_double ?? (s_double = new NotEqualDouble()));

            case TypeCode.Object:
                if (!typeInfo.IsValueType)
                {
                    return(s_reference ?? (s_reference = new NotEqualReference()));
                }
                // TODO: Nullable<T>
                throw new NotImplementedException();

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 3
0
        public static Instruction Create(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            switch ((type.IsEnum() ? Enum.GetUnderlyingType(type) : type).GetTypeCode())
            {
            case TypeCode.Boolean: return(_Boolean ?? (_Boolean = new NotEqualBoolean()));

            case TypeCode.SByte: return(_SByte ?? (_SByte = new NotEqualSByte()));

            case TypeCode.Byte: return(_Byte ?? (_Byte = new NotEqualByte()));

            case TypeCode.Char: return(_Char ?? (_Char = new NotEqualChar()));

            case TypeCode.Int16: return(_Int16 ?? (_Int16 = new NotEqualInt16()));

            case TypeCode.Int32: return(_Int32 ?? (_Int32 = new NotEqualInt32()));

            case TypeCode.Int64: return(_Int64 ?? (_Int64 = new NotEqualInt64()));

            case TypeCode.UInt16: return(_UInt16 ?? (_UInt16 = new NotEqualInt16()));

            case TypeCode.UInt32: return(_UInt32 ?? (_UInt32 = new NotEqualInt32()));

            case TypeCode.UInt64: return(_UInt64 ?? (_UInt64 = new NotEqualInt64()));

            case TypeCode.Single: return(_Single ?? (_Single = new NotEqualSingle()));

            case TypeCode.Double: return(_Double ?? (_Double = new NotEqualDouble()));

            case TypeCode.String: return(_String ?? (_Double = new NotEqualString()));

            case TypeCode.Object:
                if (!type.IsValueType())
                {
                    return(_Reference ?? (_Reference = new NotEqualReference()));
                }
                // TODO: Nullable<T>
                throw new NotImplementedException();

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 4
0
        public static Instruction Create(Type type, bool liftedToNull)
        {
            if (liftedToNull)
            {
                switch (type.GetNonNullableType().GetTypeCode())
                {
                case TypeCode.Boolean: return(ExclusiveOrInstruction.Create(type));

                case TypeCode.SByte: return(s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new NotEqualSByteLiftedToNull()));

                case TypeCode.Int16: return(s_Int16LiftedToNull ?? (s_Int16LiftedToNull = new NotEqualInt16LiftedToNull()));

                case TypeCode.Char: return(s_CharLiftedToNull ?? (s_CharLiftedToNull = new NotEqualCharLiftedToNull()));

                case TypeCode.Int32: return(s_Int32LiftedToNull ?? (s_Int32LiftedToNull = new NotEqualInt32LiftedToNull()));

                case TypeCode.Int64: return(s_Int64LiftedToNull ?? (s_Int64LiftedToNull = new NotEqualInt64LiftedToNull()));

                case TypeCode.Byte: return(s_ByteLiftedToNull ?? (s_ByteLiftedToNull = new NotEqualByteLiftedToNull()));

                case TypeCode.UInt16: return(s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new NotEqualUInt16LiftedToNull()));

                case TypeCode.UInt32: return(s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new NotEqualUInt32LiftedToNull()));

                case TypeCode.UInt64: return(s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new NotEqualUInt64LiftedToNull()));

                case TypeCode.Single: return(s_SingleLiftedToNull ?? (s_SingleLiftedToNull = new NotEqualSingleLiftedToNull()));

                default:
                    Debug.Assert(type.GetNonNullableType().GetTypeCode() == TypeCode.Double);
                    return(s_DoubleLiftedToNull ?? (s_DoubleLiftedToNull = new NotEqualDoubleLiftedToNull()));
                }
            }
            else
            {
                switch (type.GetNonNullableType().GetTypeCode())
                {
                case TypeCode.Boolean: return(s_Boolean ?? (s_Boolean = new NotEqualBoolean()));

                case TypeCode.SByte: return(s_SByte ?? (s_SByte = new NotEqualSByte()));

                case TypeCode.Int16: return(s_Int16 ?? (s_Int16 = new NotEqualInt16()));

                case TypeCode.Char: return(s_Char ?? (s_Char = new NotEqualChar()));

                case TypeCode.Int32: return(s_Int32 ?? (s_Int32 = new NotEqualInt32()));

                case TypeCode.Int64: return(s_Int64 ?? (s_Int64 = new NotEqualInt64()));

                case TypeCode.Byte: return(s_Byte ?? (s_Byte = new NotEqualByte()));

                case TypeCode.UInt16: return(s_UInt16 ?? (s_UInt16 = new NotEqualUInt16()));

                case TypeCode.UInt32: return(s_UInt32 ?? (s_UInt32 = new NotEqualUInt32()));

                case TypeCode.UInt64: return(s_UInt64 ?? (s_UInt64 = new NotEqualUInt64()));

                case TypeCode.Single: return(s_Single ?? (s_Single = new NotEqualSingle()));

                case TypeCode.Double: return(s_Double ?? (s_Double = new NotEqualDouble()));

                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 NotEqualReference()));
                }
            }
        }
Ejemplo n.º 5
0
        public static Instruction Create(Type type, bool liftedToNull)
        {
            if (liftedToNull)
            {
                // 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.Boolean: return s_booleanLiftedToNull ?? (s_booleanLiftedToNull = new NotEqualBooleanLiftedToNull());
                    case TypeCode.SByte: return s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new NotEqualSByteLiftedToNull());
                    case TypeCode.Byte: return s_byteLiftedToNull ?? (s_byteLiftedToNull = new NotEqualByteLiftedToNull());
                    case TypeCode.Char: return s_charLiftedToNull ?? (s_charLiftedToNull = new NotEqualCharLiftedToNull());
                    case TypeCode.Int16: return s_int16LiftedToNull ?? (s_int16LiftedToNull = new NotEqualInt16LiftedToNull());
                    case TypeCode.Int32: return s_int32LiftedToNull ?? (s_int32LiftedToNull = new NotEqualInt32LiftedToNull());
                    case TypeCode.Int64: return s_int64LiftedToNull ?? (s_int64LiftedToNull = new NotEqualInt64LiftedToNull());

                    case TypeCode.UInt16: return s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new NotEqualUInt16LiftedToNull());
                    case TypeCode.UInt32: return s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new NotEqualUInt32LiftedToNull());
                    case TypeCode.UInt64: return s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new NotEqualUInt64LiftedToNull());

                    case TypeCode.Single: return s_singleLiftedToNull ?? (s_singleLiftedToNull = new NotEqualSingleLiftedToNull());
                    case TypeCode.Double: return s_doubleLiftedToNull ?? (s_doubleLiftedToNull = new NotEqualDoubleLiftedToNull());

                    case TypeCode.String:
                    case TypeCode.Object:
                        if (!type.GetTypeInfo().IsValueType)
                        {
                            return s_referenceLiftedToNull ?? (s_referenceLiftedToNull = new NotEqualReferenceLiftedToNull());
                        }
                        // TODO: Nullable<T>
                        throw Error.ExpressionNotSupportedForNullableType("NotEqual", type);
                    default:
                        throw Error.ExpressionNotSupportedForType("NotEqual", type);
                }
            }
            else
            {
                // 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.Boolean: return s_boolean ?? (s_boolean = new NotEqualBoolean());
                    case TypeCode.SByte: return s_SByte ?? (s_SByte = new NotEqualSByte());
                    case TypeCode.Byte: return s_byte ?? (s_byte = new NotEqualByte());
                    case TypeCode.Char: return s_char ?? (s_char = new NotEqualChar());
                    case TypeCode.Int16: return s_int16 ?? (s_int16 = new NotEqualInt16());
                    case TypeCode.Int32: return s_int32 ?? (s_int32 = new NotEqualInt32());
                    case TypeCode.Int64: return s_int64 ?? (s_int64 = new NotEqualInt64());

                    case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new NotEqualUInt16());
                    case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new NotEqualUInt32());
                    case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new NotEqualUInt64());

                    case TypeCode.Single: return s_single ?? (s_single = new NotEqualSingle());
                    case TypeCode.Double: return s_double ?? (s_double = new NotEqualDouble());

                    case TypeCode.String:
                    case TypeCode.Object:
                        if (!type.GetTypeInfo().IsValueType)
                        {
                            return s_reference ?? (s_reference = new NotEqualReference());
                        }
                        // TODO: Nullable<T>
                        throw Error.ExpressionNotSupportedForNullableType("NotEqual", type);
                    default:
                        throw Error.ExpressionNotSupportedForType("NotEqual", type);
                }
            }
        }
Ejemplo n.º 6
0
        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 NotEqualBooleanLiftedToNull()));

                case TypeCode.SByte: return(s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new NotEqualSByteLiftedToNull()));

                case TypeCode.Byte: return(s_byteLiftedToNull ?? (s_byteLiftedToNull = new NotEqualByteLiftedToNull()));

                case TypeCode.Char: return(s_charLiftedToNull ?? (s_charLiftedToNull = new NotEqualCharLiftedToNull()));

                case TypeCode.Int16: return(s_int16LiftedToNull ?? (s_int16LiftedToNull = new NotEqualInt16LiftedToNull()));

                case TypeCode.Int32: return(s_int32LiftedToNull ?? (s_int32LiftedToNull = new NotEqualInt32LiftedToNull()));

                case TypeCode.Int64: return(s_int64LiftedToNull ?? (s_int64LiftedToNull = new NotEqualInt64LiftedToNull()));

                case TypeCode.UInt16: return(s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new NotEqualUInt16LiftedToNull()));

                case TypeCode.UInt32: return(s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new NotEqualUInt32LiftedToNull()));

                case TypeCode.UInt64: return(s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new NotEqualUInt64LiftedToNull()));

                case TypeCode.Single: return(s_singleLiftedToNull ?? (s_singleLiftedToNull = new NotEqualSingleLiftedToNull()));

                default:
                    Debug.Assert(underlyingType.GetTypeCode() == TypeCode.Double);
                    return(s_doubleLiftedToNull ?? (s_doubleLiftedToNull = new NotEqualDoubleLiftedToNull()));
                }
            }
            else
            {
                switch (underlyingType.GetTypeCode())
                {
                case TypeCode.Boolean: return(s_boolean ?? (s_boolean = new NotEqualBoolean()));

                case TypeCode.SByte: return(s_SByte ?? (s_SByte = new NotEqualSByte()));

                case TypeCode.Byte: return(s_byte ?? (s_byte = new NotEqualByte()));

                case TypeCode.Char: return(s_char ?? (s_char = new NotEqualChar()));

                case TypeCode.Int16: return(s_int16 ?? (s_int16 = new NotEqualInt16()));

                case TypeCode.Int32: return(s_int32 ?? (s_int32 = new NotEqualInt32()));

                case TypeCode.Int64: return(s_int64 ?? (s_int64 = new NotEqualInt64()));

                case TypeCode.UInt16: return(s_UInt16 ?? (s_UInt16 = new NotEqualUInt16()));

                case TypeCode.UInt32: return(s_UInt32 ?? (s_UInt32 = new NotEqualUInt32()));

                case TypeCode.UInt64: return(s_UInt64 ?? (s_UInt64 = new NotEqualUInt64()));

                case TypeCode.Single: return(s_single ?? (s_single = new NotEqualSingle()));

                case TypeCode.Double: return(s_double ?? (s_double = new NotEqualDouble()));

                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 NotEqualReference()));
                }
            }
        }
Ejemplo n.º 7
0
        public static Instruction Create(Type type, bool liftedToNull)
        {
            if (liftedToNull)
            {
                // Boxed enums can be unboxed as their underlying types:
                Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType();

                switch (underlyingType.GetTypeCode())
                {
                case TypeCode.Boolean: return(s_booleanLiftedToNull ?? (s_booleanLiftedToNull = new NotEqualBooleanLiftedToNull()));

                case TypeCode.SByte: return(s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new NotEqualSByteLiftedToNull()));

                case TypeCode.Byte: return(s_byteLiftedToNull ?? (s_byteLiftedToNull = new NotEqualByteLiftedToNull()));

                case TypeCode.Char: return(s_charLiftedToNull ?? (s_charLiftedToNull = new NotEqualCharLiftedToNull()));

                case TypeCode.Int16: return(s_int16LiftedToNull ?? (s_int16LiftedToNull = new NotEqualInt16LiftedToNull()));

                case TypeCode.Int32: return(s_int32LiftedToNull ?? (s_int32LiftedToNull = new NotEqualInt32LiftedToNull()));

                case TypeCode.Int64: return(s_int64LiftedToNull ?? (s_int64LiftedToNull = new NotEqualInt64LiftedToNull()));

                case TypeCode.UInt16: return(s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new NotEqualUInt16LiftedToNull()));

                case TypeCode.UInt32: return(s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new NotEqualUInt32LiftedToNull()));

                case TypeCode.UInt64: return(s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new NotEqualUInt64LiftedToNull()));

                case TypeCode.Single: return(s_singleLiftedToNull ?? (s_singleLiftedToNull = new NotEqualSingleLiftedToNull()));

                case TypeCode.Double: return(s_doubleLiftedToNull ?? (s_doubleLiftedToNull = new NotEqualDoubleLiftedToNull()));

                case TypeCode.String:
                case TypeCode.Object:
                    if (!type.GetTypeInfo().IsValueType)
                    {
                        return(s_referenceLiftedToNull ?? (s_referenceLiftedToNull = new NotEqualReferenceLiftedToNull()));
                    }
                    // TODO: Nullable<T>
                    throw Error.ExpressionNotSupportedForNullableType("NotEqual", type);

                default:
                    throw Error.ExpressionNotSupportedForType("NotEqual", type);
                }
            }
            else
            {
                // Boxed enums can be unboxed as their underlying types:
                Type underlyingType = type.GetTypeInfo().IsEnum ? Enum.GetUnderlyingType(type) : type.GetNonNullableType();

                switch (underlyingType.GetTypeCode())
                {
                case TypeCode.Boolean: return(s_boolean ?? (s_boolean = new NotEqualBoolean()));

                case TypeCode.SByte: return(s_SByte ?? (s_SByte = new NotEqualSByte()));

                case TypeCode.Byte: return(s_byte ?? (s_byte = new NotEqualByte()));

                case TypeCode.Char: return(s_char ?? (s_char = new NotEqualChar()));

                case TypeCode.Int16: return(s_int16 ?? (s_int16 = new NotEqualInt16()));

                case TypeCode.Int32: return(s_int32 ?? (s_int32 = new NotEqualInt32()));

                case TypeCode.Int64: return(s_int64 ?? (s_int64 = new NotEqualInt64()));

                case TypeCode.UInt16: return(s_UInt16 ?? (s_UInt16 = new NotEqualUInt16()));

                case TypeCode.UInt32: return(s_UInt32 ?? (s_UInt32 = new NotEqualUInt32()));

                case TypeCode.UInt64: return(s_UInt64 ?? (s_UInt64 = new NotEqualUInt64()));

                case TypeCode.Single: return(s_single ?? (s_single = new NotEqualSingle()));

                case TypeCode.Double: return(s_double ?? (s_double = new NotEqualDouble()));

                case TypeCode.String:
                case TypeCode.Object:
                    if (!type.GetTypeInfo().IsValueType)
                    {
                        return(s_reference ?? (s_reference = new NotEqualReference()));
                    }
                    // TODO: Nullable<T>
                    throw Error.ExpressionNotSupportedForNullableType("NotEqual", type);

                default:
                    throw Error.ExpressionNotSupportedForType("NotEqual", type);
                }
            }
        }
Ejemplo n.º 8
0
        public static Instruction CreateLifted(Type type) {
            // Boxed enums can be unboxed as their underlying types:
            switch ((type.IsEnum() ? Enum.GetUnderlyingType(type) : type).GetTypeCode()) {
                case TypeCode.Boolean: return _BooleanLifted ?? (_BooleanLifted = new NotEqualBoolean() { LiftedToNull = true });
                case TypeCode.SByte: return _SByteLifted ?? (_SByteLifted = new NotEqualSByte() { LiftedToNull = true });
                case TypeCode.Byte: return _ByteLifted ?? (_ByteLifted = new NotEqualByte() { LiftedToNull = true });
                case TypeCode.Char: return _CharLifted ?? (_CharLifted = new NotEqualChar() { LiftedToNull = true });
                case TypeCode.Int16: return _Int16Lifted ?? (_Int16Lifted = new NotEqualInt16() { LiftedToNull = true });
                case TypeCode.Int32: return _Int32Lifted ?? (_Int32Lifted = new NotEqualInt32() { LiftedToNull = true });
                case TypeCode.Int64: return _Int64Lifted ?? (_Int64Lifted = new NotEqualInt64() { LiftedToNull = true });

                case TypeCode.UInt16: return _UInt16Lifted ?? (_UInt16Lifted = new NotEqualInt16() { LiftedToNull = true });
                case TypeCode.UInt32: return _UInt32Lifted ?? (_UInt32Lifted = new NotEqualInt32() { LiftedToNull = true });
                case TypeCode.UInt64: return _UInt64Lifted ?? (_UInt64Lifted = new NotEqualInt64() { LiftedToNull = true });

                case TypeCode.Single: return _SingleLifted ?? (_SingleLifted = new NotEqualSingle() { LiftedToNull = true });
                case TypeCode.Double: return _DoubleLifted ?? (_DoubleLifted = new NotEqualDouble() { LiftedToNull = true });

                default:
                    throw Assert.Unreachable;
            }
        }
Ejemplo n.º 9
0
        public static Instruction CreateLifted(Type type)
        {
            // Boxed enums can be unboxed as their underlying types:
            switch ((type.IsEnum() ? Enum.GetUnderlyingType(type) : type).GetTypeCode())
            {
            case TypeCode.Boolean: return(_BooleanLifted ?? (_BooleanLifted = new NotEqualBoolean()
                {
                    LiftedToNull = true
                }));

            case TypeCode.SByte: return(_SByteLifted ?? (_SByteLifted = new NotEqualSByte()
                {
                    LiftedToNull = true
                }));

            case TypeCode.Byte: return(_ByteLifted ?? (_ByteLifted = new NotEqualByte()
                {
                    LiftedToNull = true
                }));

            case TypeCode.Char: return(_CharLifted ?? (_CharLifted = new NotEqualChar()
                {
                    LiftedToNull = true
                }));

            case TypeCode.Int16: return(_Int16Lifted ?? (_Int16Lifted = new NotEqualInt16()
                {
                    LiftedToNull = true
                }));

            case TypeCode.Int32: return(_Int32Lifted ?? (_Int32Lifted = new NotEqualInt32()
                {
                    LiftedToNull = true
                }));

            case TypeCode.Int64: return(_Int64Lifted ?? (_Int64Lifted = new NotEqualInt64()
                {
                    LiftedToNull = true
                }));

            case TypeCode.UInt16: return(_UInt16Lifted ?? (_UInt16Lifted = new NotEqualInt16()
                {
                    LiftedToNull = true
                }));

            case TypeCode.UInt32: return(_UInt32Lifted ?? (_UInt32Lifted = new NotEqualInt32()
                {
                    LiftedToNull = true
                }));

            case TypeCode.UInt64: return(_UInt64Lifted ?? (_UInt64Lifted = new NotEqualInt64()
                {
                    LiftedToNull = true
                }));

            case TypeCode.Single: return(_SingleLifted ?? (_SingleLifted = new NotEqualSingle()
                {
                    LiftedToNull = true
                }));

            case TypeCode.Double: return(_DoubleLifted ?? (_DoubleLifted = new NotEqualDouble()
                {
                    LiftedToNull = true
                }));

            default:
                throw Assert.Unreachable;
            }
        }
Ejemplo n.º 10
0
        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 NotEqualBooleanLiftedToNull());
                    case TypeCode.SByte: return s_SByteLiftedToNull ?? (s_SByteLiftedToNull = new NotEqualSByteLiftedToNull());
                    case TypeCode.Int16: return s_Int16LiftedToNull ?? (s_Int16LiftedToNull = new NotEqualInt16LiftedToNull());
                    case TypeCode.Char: return s_CharLiftedToNull ?? (s_CharLiftedToNull = new NotEqualCharLiftedToNull());
                    case TypeCode.Int32: return s_Int32LiftedToNull ?? (s_Int32LiftedToNull = new NotEqualInt32LiftedToNull());
                    case TypeCode.Int64: return s_Int64LiftedToNull ?? (s_Int64LiftedToNull = new NotEqualInt64LiftedToNull());
                    case TypeCode.Byte: return s_ByteLiftedToNull ?? (s_ByteLiftedToNull = new NotEqualByteLiftedToNull());
                    case TypeCode.UInt16: return s_UInt16LiftedToNull ?? (s_UInt16LiftedToNull = new NotEqualUInt16LiftedToNull());
                    case TypeCode.UInt32: return s_UInt32LiftedToNull ?? (s_UInt32LiftedToNull = new NotEqualUInt32LiftedToNull());
                    case TypeCode.UInt64: return s_UInt64LiftedToNull ?? (s_UInt64LiftedToNull = new NotEqualUInt64LiftedToNull());
                    case TypeCode.Single: return s_SingleLiftedToNull ?? (s_SingleLiftedToNull = new NotEqualSingleLiftedToNull());
                    default:
                        Debug.Assert(underlyingType.GetTypeCode() == TypeCode.Double);
                        return s_DoubleLiftedToNull ?? (s_DoubleLiftedToNull = new NotEqualDoubleLiftedToNull());
                }
            }
            else
            {
                switch (underlyingType.GetTypeCode())
                {
                    case TypeCode.Boolean: return s_Boolean ?? (s_Boolean = new NotEqualBoolean());
                    case TypeCode.SByte: return s_SByte ?? (s_SByte = new NotEqualSByte());
                    case TypeCode.Int16: return s_Int16 ?? (s_Int16 = new NotEqualInt16());
                    case TypeCode.Char: return s_Char ?? (s_Char = new NotEqualChar());
                    case TypeCode.Int32: return s_Int32 ?? (s_Int32 = new NotEqualInt32());
                    case TypeCode.Int64: return s_Int64 ?? (s_Int64 = new NotEqualInt64());
                    case TypeCode.Byte: return s_Byte ?? (s_Byte = new NotEqualByte());
                    case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new NotEqualUInt16());
                    case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new NotEqualUInt32());
                    case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new NotEqualUInt64());
                    case TypeCode.Single: return s_Single ?? (s_Single = new NotEqualSingle());
                    case TypeCode.Double: return s_Double ?? (s_Double = new NotEqualDouble());
                    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 NotEqualReference());
                }
            }
        }
Ejemplo n.º 11
0
        public static Instruction Create(Type type)
        {
            var typeInfo = type.GetTypeInfo();
            // Boxed enums can be unboxed as their underlying types:
            var typeToUse = typeInfo.IsEnum ? Enum.GetUnderlyingType(type) : type;
            switch (typeToUse.GetTypeCode())
            {
                case TypeCode.Boolean: return s_boolean ?? (s_boolean = new NotEqualBoolean());
                case TypeCode.SByte: return s_SByte ?? (s_SByte = new NotEqualSByte());
                case TypeCode.Byte: return s_byte ?? (s_byte = new NotEqualByte());
                case TypeCode.Char: return s_char ?? (s_char = new NotEqualChar());
                case TypeCode.Int16: return s_int16 ?? (s_int16 = new NotEqualInt16());
                case TypeCode.Int32: return s_int32 ?? (s_int32 = new NotEqualInt32());
                case TypeCode.Int64: return s_int64 ?? (s_int64 = new NotEqualInt64());

                case TypeCode.UInt16: return s_UInt16 ?? (s_UInt16 = new NotEqualInt16());
                case TypeCode.UInt32: return s_UInt32 ?? (s_UInt32 = new NotEqualInt32());
                case TypeCode.UInt64: return s_UInt64 ?? (s_UInt64 = new NotEqualInt64());

                case TypeCode.Single: return s_single ?? (s_single = new NotEqualSingle());
                case TypeCode.Double: return s_double ?? (s_double = new NotEqualDouble());

                case TypeCode.Object:
                    if (!typeInfo.IsValueType)
                    {
                        return s_reference ?? (s_reference = new NotEqualReference());
                    }
                    // TODO: Nullable<T>
                    throw new NotImplementedException();

                default:
                    throw new NotImplementedException();
            }
        }