Ejemplo n.º 1
0
            public static DescriptorComparison CheckNumericCompatibility(TypeDescriptor leftDeclaredDescriptor, TypeDescriptor rightDeclaredDescriptor, TypeDescriptor leftActualDescriptor, TypeDescriptor rightActualDescriptor)
            {
                var ld = leftDeclaredDescriptor;
                var rd = rightDeclaredDescriptor;

                var leftNumeric  = CodeFlow.IsPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
                var rightNumeric = CodeFlow.IsPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);

                // If the declared descriptors aren't providing the information, try the actual descriptors
                if (!leftNumeric && !ObjectUtils.NullSafeEquals(ld, leftActualDescriptor))
                {
                    ld          = leftActualDescriptor;
                    leftNumeric = CodeFlow.IsPrimitiveOrUnboxableSupportedNumberOrBoolean(ld);
                }

                if (!rightNumeric && !ObjectUtils.NullSafeEquals(rd, rightActualDescriptor))
                {
                    rd           = rightActualDescriptor;
                    rightNumeric = CodeFlow.IsPrimitiveOrUnboxableSupportedNumberOrBoolean(rd);
                }

                if (leftNumeric && rightNumeric)
                {
                    if (CodeFlow.AreBoxingCompatible(ld, rd))
                    {
                        return(new DescriptorComparison(true, true, CodeFlow.ToPrimitiveTargetDescriptor(ld)));
                    }
                    else
                    {
                        return(INCOMPATIBLE_NUMBERS);
                    }
                }
                else
                {
                    return(NOT_NUMBERS);
                }
            }