Exemple #1
0
 public void WriteTo(TranslationBuffer buffer)
 {
     _subject.WriteTo(buffer);
     buffer.WriteToTranslation('[');
     _parameters.WithoutParentheses().WriteTo(buffer);
     buffer.WriteToTranslation(']');
 }
        public void WriteTo(TranslationBuffer buffer)
        {
            buffer.WriteToTranslation("try");
            _bodyTranslation.WriteTo(buffer);

            for (int i = 0, l = _catchBlockTranslations.Count; i < l; ++i)
            {
                buffer.WriteNewLineToTranslation();
                _catchBlockTranslations[i].WriteTo(buffer);
            }

            if (_hasFault)
            {
                buffer.WriteNewLineToTranslation();
                buffer.WriteToTranslation("fault");
                _faultTranslation.WriteTo(buffer);
            }

            if (_hasFinally)
            {
                buffer.WriteNewLineToTranslation();
                buffer.WriteToTranslation("finally");
                _finallyTranslation.WriteTo(buffer);
            }
        }
Exemple #3
0
            public void WriteTo(TranslationBuffer buffer)
            {
                buffer.WriteToTranslation("new ");

                if (_typeName.Length != 0)
                {
                    buffer.WriteToTranslation(_typeName);
                    buffer.WriteSpaceToTranslation();
                }

                buffer.WriteToTranslation("{ ");

                if (_ctorParameters.Length != 0)
                {
                    for (var i = 0; ;)
                    {
                        buffer.WriteToTranslation(_ctorParameters[i].Name);
                        buffer.WriteToTranslation(" = ");
                        Parameters[i].WriteTo(buffer);

                        if (++i == _ctorParameters.Length)
                        {
                            break;
                        }

                        buffer.WriteToTranslation(", ");
                    }
                }

                buffer.WriteToTranslation(" }");
            }
Exemple #4
0
        public void WriteTo(TranslationBuffer buffer)
        {
            if (_hasVariables)
            {
                foreach (var parametersByType in _variables)
                {
                    parametersByType.Key.WriteTo(buffer);
                    buffer.WriteSpaceToTranslation();
                    parametersByType.Value.WriteTo(buffer);
                    buffer.WriteToTranslation(';');
                    buffer.WriteNewLineToTranslation();
                }

                switch (_statements[0].NodeType)
                {
                case Conditional when !ConditionalTranslation.IsTernary(_statements[0].Expression):
                case Switch:
                    buffer.WriteNewLineToTranslation();
                    break;
                }
            }

            for (var i = 0; ;)
            {
                _statements[i].WriteTo(buffer);

                if (++i == _statementCount)
                {
                    break;
                }

                buffer.WriteNewLineToTranslation();
            }
        }
 public void WriteTo(TranslationBuffer buffer)
 {
     _operandTranslation.WriteTo(buffer);
     buffer.WriteToTranslation(_typeOf);
     _typeNameTranslation.WriteTo(buffer);
     buffer.WriteToTranslation(')');
 }
 public override void WriteTo(TranslationBuffer buffer)
 {
     WriteIfStatement(buffer);
     buffer.WriteNewLineToTranslation();
     buffer.WriteNewLineToTranslation();
     IfFalseTranslation.WriteTo(buffer);
 }
 public virtual void WriteTo(TranslationBuffer buffer)
 {
     buffer.WriteToTranslation(" (");
     _exceptionTypeTranslation.WriteTo(buffer);
     buffer.WriteSpaceToTranslation();
     buffer.WriteToTranslation(_variableName);
     buffer.WriteToTranslation(')');
 }
 private static void WriteTimeSpanHoursMinutesSeconds(TranslationBuffer buffer, TimeSpan timeSpan)
 {
     buffer.WriteToTranslation(timeSpan.Hours);
     buffer.WriteToTranslation(", ");
     buffer.WriteToTranslation(timeSpan.Minutes);
     buffer.WriteToTranslation(", ");
     buffer.WriteToTranslation(timeSpan.Seconds);
 }
 private void WriteSingleLineTernary(TranslationBuffer buffer)
 {
     TestTranslation.WriteInParenthesesIfRequired(buffer);
     buffer.WriteToTranslation(" ? ");
     IfTrueTranslation.WriteTo(buffer);
     buffer.WriteToTranslation(" : ");
     IfFalseTranslation.WriteTo(buffer);
 }
Exemple #10
0
        public string GetTranslation()
        {
            var buffer = new TranslationBuffer(_root.EstimatedSize);

            _root.WriteTo(buffer);

            return(buffer.GetContent());
        }
        public void WriteTo(TranslationBuffer buffer)
        {
            _parameters.WriteTo(buffer);

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

            _bodyTranslation.WriteTo(buffer);
        }
Exemple #12
0
 public void WriteTo(TranslationBuffer buffer)
 {
     WriteOpeningCheckedIfNecessary(buffer, out var isMultiStatementChecked);
     _leftOperandTranslation.WriteInParenthesesIfRequired(buffer);
     buffer.WriteToTranslation(_operator);
     _rightOperandTranslation.WriteInParenthesesIfRequired(buffer);
     WriteClosingCheckedIfNecessary(buffer, isMultiStatementChecked);
 }
Exemple #13
0
 public void WriteTo(TranslationBuffer buffer)
 {
     _binaryConditionLeftTranslation.WriteInParenthesesIfRequired(buffer);
     buffer.WriteToTranslation(_binaryConditionOperator.TrimEnd());
     buffer.WriteNewLineToTranslation();
     buffer.Indent();
     _binaryConditionRightTranslation.WriteInParenthesesIfRequired(buffer);
     buffer.Unindent();
 }
Exemple #14
0
            protected virtual void WriteStatementTo(TranslationBuffer buffer)
            {
                _statementTranslation.WriteTo(buffer);

                if (_statementIsUnterminated && (DoNotTerminate == false))
                {
                    buffer.WriteToTranslation(';');
                }
            }
            public void WriteTo(TranslationBuffer buffer)
            {
                if (_useLiteralPrefix)
                {
                    buffer.WriteToTranslation('@');
                }

                buffer.WriteToTranslation(_parameter.Name);
            }
        private bool WriteEmptyCodeBlock(TranslationBuffer buffer)
        {
            if ((_translation is IPotentialEmptyTranslatable emptyTranslatable) && emptyTranslatable.IsEmpty)
            {
                buffer.WriteClosingBraceToTranslation(startOnNewLine: false);
                return(true);
            }

            return(false);
        }
Exemple #17
0
            public void WriteTo(TranslationBuffer buffer)
            {
                if (_standaloneBoolean.IsComparisonToTrue)
                {
                    _operandTranslation.WriteTo(buffer);
                    return;
                }

                NegationTranslation.ForNot(_operandTranslation).WriteTo(buffer);
            }
        public void WriteTo(TranslationBuffer buffer)
        {
            if (_isObject)
            {
                buffer.WriteToTranslation(_writeObjectTypeName ? "Object" : _object);
                return;
            }

            buffer.WriteFriendlyName(Type, _translationSettings);
        }
Exemple #19
0
        public void WriteTo(TranslationBuffer buffer)
        {
            if (_subject != null)
            {
                _subject.WriteInParenthesesIfRequired(buffer);
                buffer.WriteToTranslation('.');
            }

            buffer.WriteToTranslation(_memberName);
        }
        public static void WriteClosingBraceToTranslation(this TranslationBuffer buffer, bool startOnNewLine = true)
        {
            if (startOnNewLine)
            {
                buffer.WriteNewLineToTranslation();
            }

            buffer.Unindent();
            buffer.WriteToTranslation('}');
        }
            public void WriteTo(TranslationBuffer buffer)
            {
                if (TryWriteFactoryMethodCall(_timeSpan.Days, _timeSpan.TotalDays, "Days", buffer))
                {
                    return;
                }

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

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

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

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

                if ((_timeSpan.Days == 0) && (_timeSpan.Hours == 0) && (_timeSpan.Minutes == 0) && (_timeSpan.Seconds == 0))
                {
                    buffer.WriteToTranslation("TimeSpan.FromTicks(");
                    buffer.WriteToTranslation(Math.Floor(_timeSpan.TotalMilliseconds * 10000).ToString(CurrentCulture));
                    goto EndTranslation;
                }

                buffer.WriteToTranslation("new TimeSpan(");

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

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

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

EndTranslation:
                buffer.WriteToTranslation(')');
            }
        public static void WriteOpeningBraceToTranslation(this TranslationBuffer buffer, bool startOnNewLine = true)
        {
            if (startOnNewLine && buffer.TranslationQuery(q => !q.TranslationEndsWith('{')))
            {
                buffer.WriteNewLineToTranslation();
            }

            buffer.WriteToTranslation('{');
            buffer.WriteNewLineToTranslation();
            buffer.Indent();
        }
        public void WriteTo(TranslationBuffer buffer)
        {
            buffer.WriteToTranslation(_throw);

            if (_thrownItemTranslation == null)
            {
                return;
            }

            buffer.WriteSpaceToTranslation();
            _thrownItemTranslation.WriteTo(buffer);
        }
Exemple #24
0
            public void WriteTo(TranslationBuffer buffer)
            {
                buffer.WriteToTranslation("new ");
                _typeNameTranslation.WriteTo(buffer);

                if (_omitParenthesesIfParameterless && Parameters.None)
                {
                    return;
                }

                Parameters.WithParentheses().WriteTo(buffer);
            }
            public override void WriteTo(TranslationBuffer buffer)
            {
                WriteIfStatement(buffer);
                buffer.WriteNewLineToTranslation();
                buffer.WriteToTranslation("else");

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

                IfFalseTranslation.WriteTo(buffer);
            }
            private static void WriteTwoDigitDatePart(int datePart, TranslationBuffer buffer)
            {
                buffer.WriteToTranslation(", ");

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

                buffer.WriteToTranslation('0');
                buffer.WriteToTranslation(datePart);
            }
            public void WriteTo(TranslationBuffer buffer)
            {
                if (_useLiteralPrefix)
                {
                    buffer.WriteToTranslation('@');
                }

                buffer.WriteToTranslation(_parameterName);

                if (_variableNumber != null)
                {
                    buffer.WriteToTranslation(_variableNumber.Value.ToString());
                }
            }
        private void WriteDefaultIfPresent(TranslationBuffer buffer)
        {
            if (_defaultCaseTranslation == null)
            {
                return;
            }

            buffer.WriteNewLineToTranslation();
            buffer.WriteNewLineToTranslation();
            buffer.WriteToTranslation("default:");
            buffer.WriteNewLineToTranslation();

            WriteCaseBody(_defaultCaseTranslation, buffer);
        }
        private static void WriteCaseBody(ITranslation bodyTranslation, TranslationBuffer buffer)
        {
            buffer.Indent();

            bodyTranslation.WriteTo(buffer);

            if (WriteBreak(bodyTranslation))
            {
                buffer.WriteNewLineToTranslation();
                buffer.WriteToTranslation("break;");
            }

            buffer.Unindent();
        }
Exemple #30
0
        public void WriteTo(TranslationBuffer buffer)
        {
            if (_operatorIsSuffix == false)
            {
                buffer.WriteToTranslation(_operator);
            }

            _operandTranslation?.WriteTo(buffer);

            if (_operatorIsSuffix)
            {
                buffer.WriteToTranslation(_operator);
            }
        }