示例#1
0
        public override bool Equals(OrderedLiteralBase other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            switch (other)
            {
            case CharLiteral charLiteral:
                return(Equals(charLiteral));

            case FloatLiteral floatLiteral:
                return(Equals(IntegerLiteral.From((long)floatLiteral.Value)));

            case IntegerLiteral integerLiteral:
                return(Equals(new CharLiteral(integerLiteral)));

            default:
                throw new ArgumentOutOfRangeException(nameof(other));
            }
        }
        public override int CompareTo(OrderedLiteralBase other)
        {
            if (ReferenceEquals(this, other))
            {
                return(0);
            }
            if (ReferenceEquals(null, other))
            {
                return(1);
            }
            switch (other)
            {
            case CharLiteral charLiteral:
                return(CompareTo(new FloatLiteral(IntegerLiteral.From(charLiteral.Value))));

            case FloatLiteral floatLiteral:
                return(CompareTo(floatLiteral));

            case IntegerLiteral integerLiteral:
                return(CompareTo(new FloatLiteral(integerLiteral)));

            default:
                throw new ArgumentOutOfRangeException(nameof(other));
            }
        }
示例#3
0
        public CharLiteral([NotNull] OrderedLiteralBase other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            switch (other)
            {
            case CharLiteral charLiteral:
                Value = charLiteral.Value;
                break;

            case FloatLiteral floatLiteral:
                Value = (char)floatLiteral.Value;
                break;

            case IntegerLiteral integerLiteral:
                Value = checked ((char)((long)integerLiteral.AbsoluteValue * integerLiteral.Sign));

                if (integerLiteral.Sign == 0 && integerLiteral.AbsoluteValue != 0)
                {
                    throw new ArgumentException(nameof(integerLiteral));
                }

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(other));
            }
        }
        public IntegerLiteral([NotNull] OrderedLiteralBase other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            switch (other)
            {
            case CharLiteral charLiteral:
                AbsoluteValue = (ulong)Math.Abs(charLiteral.Value);
                Sign          = Math.Sign(charLiteral.Value);
                break;

            case FloatLiteral floatLiteral:
                AbsoluteValue = (ulong)Math.Abs(floatLiteral.Value);
                Sign          = Math.Sign(floatLiteral.Value);
                break;

            case IntegerLiteral integerLiteral:
                AbsoluteValue = integerLiteral.AbsoluteValue;
                Sign          = integerLiteral.Sign;

                if (integerLiteral.Sign == 0 && integerLiteral.AbsoluteValue != 0)
                {
                    throw new ArgumentException(nameof(integerLiteral));
                }

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(other));
            }
        }