Beispiel #1
0
            public override object VisitAmountSignedConvertible(CurrencyComputerParser.AmountSignedConvertibleContext context)
            {
                var amountSigned = (AmountSigned)VisitAmountSigned(context.amountSigned());

                var conversionStr = (string)VisitConversion(context.conversion());
                var convertTo     = _conversionToCurrencyConventions[conversionStr];

                return(ConvertTo(amountSigned, convertTo));
            }
Beispiel #2
0
            public override object VisitAmountSignedConvertible(CurrencyComputerParser.AmountSignedConvertibleContext context)
            {
                var amountSigned = (AmountSigned)VisitAmountSigned(context.amountSigned());

                // Контроль типов: нельзя конвертировать валюту в саму себя
                if (amountSigned.Amount.Currency == _targetCurrency)
                {
                    throw new SyntaxException($"Can't convert {context.GetText()}, because {amountSigned.Amount.Currency} is destination currency.");
                }

                var conversionStr = (string)VisitConversion(context.conversion());
                var convertTo     = _conversionToCurrencyConventions[conversionStr];

                var converted = ConvertTo(amountSigned, convertTo);

                if (converted != amountSigned)
                {
                    _logger?.LogDebug("{OperationNumber}:Converted from {Source} to {Dest}.", _operationsLogger++, amountSigned, converted);
                }

                return(converted);
            }