小编whi*_*hes的帖子

T4模板空白行或换行符

有没有办法指示T4模板生成空白行或换行符?

我意识到我可以在已经包含一些文本的块中输出空格。但是,当我没有文本要输出时该怎么办?我只想输出一个空白行。例如,在方法调用之间。

@TobiMcNamobi

我正在尝试以下方法调用之间使用'#>'和'<#+'标签的所有方式。我似乎偶然发现了一种有效的技术('#> <#+'),但是我不明白为什么它起作用。据我所知,我正在指示模板输出一个空格。

<#+
public class Blah
{
    /// <summary>
    /// Generates properties.
    /// </summary>
    /// <param name="codeInterface">The interface containing the properties collection.</param>
    public void GenerateProperties(string blah)
        {
            IEnumerable<String> properties = codeInterface.Properties;

            foreach (var property in properties)
            {
                if (!codeInterface.IsInterface)
                    {
                        this.GeneratePrivateVariable(property);
                    }
            }#> <#+

            foreach (var property in properties)
            {
                if (codeInterface.IsInterface)
                {
                    this.GenerateInterfaceProperty(property);
                }
                else
                {
                    this.GenerateClassProperty(property, codeInterface as string);
                }
            }
        }
#>
Run Code Online (Sandbox Code Playgroud)

编辑:起初似乎很有效。我按照上面的方法生成了它,并且生成了我期望的输出。现在没有。这样做:

                    }
            }#> (<-- a single space here, after the tag)
<#+ …
Run Code Online (Sandbox Code Playgroud)

t4 templates

5
推荐指数
1
解决办法
1597
查看次数

标签 统计

t4 ×1

templates ×1