コード例 #1
0
 public void WriteTo(TranslationWriter writer)
 {
     _subject.WriteTo(writer);
     writer.WriteToTranslation('[');
     _parameters.WithoutParentheses().WriteTo(writer);
     writer.WriteToTranslation(']');
 }
コード例 #2
0
            public void WriteTo(TranslationWriter writer)
            {
                writer.WriteNewToTranslation();
                writer.WriteTypeNameToTranslation(nameof(DateTime));
                writer.WriteToTranslation('(');

                writer.WriteToTranslation(_value.Year);
                WriteTwoDigitDatePart(_value.Month, writer);
                WriteTwoDigitDatePart(_value.Day, writer);

                if (_hasMilliseconds || _hasTime)
                {
                    WriteTwoDigitDatePart(_value.Hour, writer);
                    WriteTwoDigitDatePart(_value.Minute, writer);
                    WriteTwoDigitDatePart(_value.Second, writer);

                    if (_hasMilliseconds)
                    {
                        writer.WriteToTranslation(", ");
                        writer.WriteToTranslation(_value.Millisecond);
                    }
                }

                writer.WriteToTranslation(")");
            }
コード例 #3
0
        public void WriteTo(TranslationWriter writer)
        {
            writer.WriteNewToTranslation();
            _typeNameTranslation.WriteTo(writer);
            writer.WriteToTranslation('[');

            if (_boundTranslationCount != 0)
            {
                for (var i = 0; ;)
                {
                    _boundTranslations[i].WriteTo(writer);

                    ++i;

                    if (i == _boundTranslationCount)
                    {
                        break;
                    }

                    writer.WriteToTranslation("[]");
                }
            }

            writer.WriteToTranslation(']');
        }
コード例 #4
0
 public void WriteTo(TranslationWriter writer)
 {
     writer.WriteNewLineToTranslation();
     writer.WriteKeywordToTranslation("catch");
     _exceptionClause?.WriteTo(writer);
     _catchBodyTranslation.WriteTo(writer);
 }
コード例 #5
0
            private static bool TryWriteFactoryMethodCall(
                long value,
                double totalValue,
                string valueName,
                TranslationWriter writer)
            {
                if (value == 0)
                {
                    return(false);
                }

                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (value != totalValue)
                {
                    return(false);
                }

                var factoryMethodName = "From" + valueName;

                writer.WriteTypeNameToTranslation(nameof(TimeSpan));
                writer.WriteDotToTranslation();
                writer.WriteToTranslation(factoryMethodName, MethodName);
                writer.WriteToTranslation('(');
                writer.WriteToTranslation(value);
                writer.WriteToTranslation(')');
                return(true);
            }
コード例 #6
0
 public override void WriteTo(TranslationWriter writer)
 {
     WriteIfStatement(writer);
     writer.WriteNewLineToTranslation();
     writer.WriteNewLineToTranslation();
     IfFalseTranslation.WriteTo(writer);
 }
コード例 #7
0
            private void WriteGenericArgumentNamesIfNecessary(TranslationWriter writer)
            {
                if (_explicitGenericArgumentCount == 0)
                {
                    return;
                }

                writer.WriteToTranslation('<');

                for (var i = 0; ;)
                {
                    _explicitGenericArguments[i].WriteTo(writer);

                    ++i;

                    if (i == _explicitGenericArgumentCount)
                    {
                        break;
                    }

                    writer.WriteToTranslation(", ");
                }

                writer.WriteToTranslation('>');
            }
        public void WriteTo(TranslationWriter writer)
        {
            for (var i = 0; ;)
            {
                var operandTranslation = _operandTranslations[i];

                if ((operandTranslation.NodeType == ExpressionType.Conditional) || operandTranslation.IsAssignment())
                {
                    operandTranslation.WriteInParentheses(writer);
                }
                else
                {
                    operandTranslation.WriteTo(writer);
                }

                ++i;

                if (i == _operandCount)
                {
                    break;
                }

                writer.WriteToTranslation(" + ");
            }
        }
コード例 #9
0
            public void WriteTo(TranslationWriter writer)
            {
                if (TryWriteFactoryMethodCall(_timeSpan.Days, _timeSpan.TotalDays, "Days", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Hours, _timeSpan.TotalHours, "Hours", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Minutes, _timeSpan.TotalMinutes, "Minutes", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Seconds, _timeSpan.TotalSeconds, "Seconds", writer))
                {
                    return;
                }

                if (TryWriteFactoryMethodCall(_timeSpan.Milliseconds, _timeSpan.TotalMilliseconds, "Milliseconds", writer))
                {
                    return;
                }

                if ((_timeSpan.Days == 0) && (_timeSpan.Hours == 0) && (_timeSpan.Minutes == 0) && (_timeSpan.Seconds == 0))
                {
                    writer.WriteTypeNameToTranslation(nameof(TimeSpan));
                    writer.WriteDotToTranslation();
                    writer.WriteToTranslation("FromTicks", MethodName);
                    writer.WriteToTranslation('(');
                    writer.WriteToTranslation(Math.Floor(_timeSpan.TotalMilliseconds * 10000).ToString(CurrentCulture));
                    goto EndTranslation;
                }

                writer.WriteNewToTranslation();
                writer.WriteTypeNameToTranslation(nameof(TimeSpan));
                writer.WriteToTranslation('(');

                if (_timeSpan.Days == 0)
                {
                    WriteTimeSpanHoursMinutesSeconds(writer, _timeSpan);
                    goto EndTranslation;
                }

                writer.WriteToTranslation(_timeSpan.Days);
                writer.WriteToTranslation(", ");
                WriteTimeSpanHoursMinutesSeconds(writer, _timeSpan);

                if (_timeSpan.Milliseconds != 0)
                {
                    writer.WriteToTranslation(", ");
                    writer.WriteToTranslation(_timeSpan.Milliseconds);
                }

EndTranslation:
                writer.WriteToTranslation(')');
            }
コード例 #10
0
 public virtual void WriteTo(TranslationWriter writer)
 {
     writer.WriteToTranslation(" (");
     _exceptionTypeTranslation.WriteTo(writer);
     writer.WriteSpaceToTranslation();
     writer.WriteToTranslation(_variableName, Variable);
     writer.WriteToTranslation(')');
 }
コード例 #11
0
        public void WriteTo(TranslationWriter writer)
        {
            _parameters.WriteTo(writer);

            writer.WriteToTranslation(_bodyTranslation.HasBraces ? " =>" : _fatArrow);

            _bodyTranslation.WriteTo(writer);
        }
コード例 #12
0
 private static void WriteTimeSpanHoursMinutesSeconds(TranslationWriter writer, TimeSpan timeSpan)
 {
     writer.WriteToTranslation(timeSpan.Hours);
     writer.WriteToTranslation(", ");
     writer.WriteToTranslation(timeSpan.Minutes);
     writer.WriteToTranslation(", ");
     writer.WriteToTranslation(timeSpan.Seconds);
 }
コード例 #13
0
 public void WriteTo(TranslationWriter writer)
 {
     writer.WriteControlStatementToTranslation("while ");
     writer.WriteToTranslation('(');
     writer.WriteKeywordToTranslation("true");
     writer.WriteToTranslation(')');
     _loopBodyTranslation.WriteTo(writer);
 }
コード例 #14
0
 private void WriteSingleLineTernary(TranslationWriter writer)
 {
     TestTranslation.WriteInParenthesesIfRequired(writer, _context);
     writer.WriteToTranslation(" ? ");
     IfTrueTranslation.WriteTo(writer);
     writer.WriteToTranslation(" : ");
     IfFalseTranslation.WriteTo(writer);
 }
コード例 #15
0
 public void WriteTo(TranslationWriter writer)
 {
     _binaryConditionLeftTranslation.WriteInParenthesesIfRequired(writer, _context);
     writer.WriteToTranslation(_binaryConditionOperator.TrimEnd());
     writer.WriteNewLineToTranslation();
     writer.Indent();
     _binaryConditionRightTranslation.WriteInParenthesesIfRequired(writer, _context);
     writer.Unindent();
 }
コード例 #16
0
            protected virtual void WriteStatementTo(TranslationWriter writer)
            {
                _statementTranslation.WriteTo(writer);

                if (_statementIsUnterminated && (DoNotTerminate == false))
                {
                    writer.WriteToTranslation(';');
                }
            }
コード例 #17
0
            public override void WriteTo(TranslationWriter writer)
            {
                if (this.ExceedsLengthThreshold())
                {
                    WriteMultiLineTernary(writer);
                    return;
                }

                WriteSingleLineTernary(writer);
            }
コード例 #18
0
        private bool WriteEmptyCodeBlock(TranslationWriter writer)
        {
            if (_isEmptyTranslation)
            {
                writer.WriteClosingBraceToTranslation(startOnNewLine: false);
                return(true);
            }

            return(false);
        }
コード例 #19
0
            public void WriteTo(TranslationWriter writer)
            {
                if (_typeNameTranslation != null)
                {
                    _typeNameTranslation.WriteTo(writer);
                    writer.WriteSpaceToTranslation();
                }

                writer.WriteToTranslation(_parameterName, Variable);
            }
コード例 #20
0
        public void WriteTo(TranslationWriter writer)
        {
            if (_subject != null)
            {
                _subject.WriteInParenthesesIfRequired(writer, _context);
                writer.WriteDotToTranslation();
            }

            writer.WriteToTranslation(_memberName);
        }
コード例 #21
0
        public static void WriteClosingBraceToTranslation(this TranslationWriter writer, bool startOnNewLine = true)
        {
            if (startOnNewLine)
            {
                writer.WriteNewLineToTranslation();
            }

            writer.Unindent();
            writer.WriteToTranslation('}');
        }
コード例 #22
0
        public static void WriteOpeningBraceToTranslation(this TranslationWriter writer, bool startOnNewLine = true)
        {
            if (startOnNewLine && writer.TranslationQuery(q => !q.TranslationEndsWith('{')))
            {
                writer.WriteNewLineToTranslation();
            }

            writer.WriteToTranslation('{');
            writer.WriteNewLineToTranslation();
            writer.Indent();
        }
コード例 #23
0
        public void WriteTo(TranslationWriter writer)
        {
            writer.WriteKeywordToTranslation(_throw);

            if (_thrownItemTranslation == null)
            {
                return;
            }

            writer.WriteSpaceToTranslation();
            _thrownItemTranslation.WriteTo(writer);
        }
コード例 #24
0
            public override void WriteTo(TranslationWriter writer)
            {
                WriteIfStatement(writer);
                writer.WriteNewLineToTranslation();
                writer.WriteControlStatementToTranslation("else");

                if (_isElseIf)
                {
                    writer.WriteSpaceToTranslation();
                }

                IfFalseTranslation.WriteTo(writer);
            }
コード例 #25
0
            private static void WriteTwoDigitDatePart(int datePart, TranslationWriter writer)
            {
                writer.WriteToTranslation(", ");

                if (datePart > 9)
                {
                    writer.WriteToTranslation(datePart);
                    return;
                }

                writer.WriteToTranslation(0);
                writer.WriteToTranslation(datePart);
            }
コード例 #26
0
        public static void WriteInParenthesesIfRequired(
            this ITranslation translation,
            TranslationWriter writer,
            ITranslationContext context)
        {
            if (ShouldWriteInParentheses(translation))
            {
                translation.WriteInParentheses(writer);
                return;
            }

            new CodeBlockTranslation(translation, context).WriteTo(writer);
        }
コード例 #27
0
        public void WriteTo(TranslationWriter writer)
        {
            _initializers.IsLongTranslation = TranslationSize > 40;

            writer.WriteNewToTranslation();

            if (_typeName.Length != 0)
            {
                writer.WriteTypeNameToTranslation(_typeName);
                writer.WriteSpaceToTranslation();
            }

            _initializers.WriteTo(writer);
        }
コード例 #28
0
        private void WriteDefaultIfPresent(TranslationWriter writer)
        {
            if (_defaultCaseTranslation == null)
            {
                return;
            }

            writer.WriteNewLineToTranslation();
            writer.WriteNewLineToTranslation();
            writer.WriteControlStatementToTranslation("default:");
            writer.WriteNewLineToTranslation();

            WriteCaseBody(_defaultCaseTranslation, writer);
        }
コード例 #29
0
        private static void WriteCaseBody(ITranslation bodyTranslation, TranslationWriter writer)
        {
            writer.Indent();

            bodyTranslation.WriteTo(writer);

            if (WriteBreak(bodyTranslation))
            {
                writer.WriteNewLineToTranslation();
                writer.WriteControlStatementToTranslation("break;");
            }

            writer.Unindent();
        }
コード例 #30
0
            protected override void WriteStatementTo(TranslationWriter writer)
            {
                if (_typeNameTranslation != null)
                {
                    _typeNameTranslation.WriteTo(writer);
                }
                else
                {
                    writer.WriteKeywordToTranslation(_var);
                }

                writer.WriteSpaceToTranslation();

                base.WriteStatementTo(writer);
            }