Is there a way to instruct a T4 template to generate a blank line or line break?
I realize that I can output whitespace in a block which already contains some text. But what about the case when I don't have text to output? I'd like to simply output a blank line. For example, between method calls.
@TobiMcNamobi
I was trying all manner of the usage of the '#>' and '<#+' tags between the method calls below. I seem to have stumbled upon a technique which works ('#> <#+'), but I don't understand why it works. For all I can tell, I'm instructing the template to output a Space.
<#+
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);
}
}
}
#>
Edit: It seemed to work at first. I generated as per the above and it generated the output I expected. Now it does not. This does:
}
}#> (<-- a single space here, after the tag)
<#+
foreach (var property in properties)
It's rather difficult to convey visually. In essence:
I don't know if this is the correct way, but it seems to work.
You example writes one space on the "empty" line. To fix it you can use Write("\r\n");
In your example:
foreach (var property in properties)
{
if (!codeInterface.IsInterface)
{
this.GeneratePrivateVariable(property);
}
}
Write("\r\n");
foreach (var property in properties)
{
This should put new line to the generated file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With