/// <summary>
        /// Handles a code block: depending of whether it's a feature or transform text result,
        /// it is not added to the same part of the C# file.
        /// </summary>
        /// <param name="codeBlock">The code block.</param>
        private void HandleCodeBlock([NotNull] IT4CodeBlock codeBlock)
        {
            IT4Token codeToken = codeBlock.GetCodeToken();

            if (codeToken == null)
            {
                return;
            }

            GenerationResult result;
            var expressionBlock = codeBlock as T4ExpressionBlock;

            if (expressionBlock != null)
            {
                result = _rootFeatureStarted && _includeDepth == 0 ? _featureResult : _transformTextResult;
                result.Builder.Append("this.Write(__\x200CToString(");
            }
            else
            {
                if (codeBlock is T4FeatureBlock)
                {
                    if (_includeDepth == 0)
                    {
                        _rootFeatureStarted = true;
                    }
                    result = _featureResult;
                }
                else
                {
                    result = _transformTextResult;
                }
            }

            result.Builder.Append(CodeCommentStart);
            result.AppendMapped(codeToken);
            result.Builder.Append(CodeCommentEnd);

            if (expressionBlock != null)
            {
                result.Builder.Append("));");
            }
            result.Builder.AppendLine();
        }
Beispiel #2
0
 private static bool HasLineBreak([NotNull] IT4CodeBlock codeBlock, int nodeStart, TreeOffset blockStart) =>
 codeBlock.GetText().Substring(0, nodeStart - blockStart.Offset).IndexOf('\n') >= 0;