Reading Code Generation and T4 Text Templates and I found this syntax <#= DateTime.Now #>
<html><body>
The date and time now is: <#= DateTime.Now #>
</body></html>
How is it different from <%= DateTime.Now %>
or <%# DateTime.Now %>
.
Google search showed nothing
I can't claim to be really familiar with T4 text templates, but it appears the difference is between design/build time code generation (which can include executable statements) and runtime code execution.
So <#= #>
evaluates an expression within a template that is used to generate a file.
And <%= %>
executes the code within the block and writes it to the output stream. This will be JIT-compiled when the page is first executed, but the point is that it denotes a block of code to execute when the page runs, not during generation of a templated file.
The third form, <%# %>
denotes a databinding expression, also evaluated when the page executes.
Expression control blocks
An expression control block evaluates an expression and converts it to a string. This is inserted into the output file.
Expression control blocks are delimted by the symbols <#= ... #>
For example, the following control block causes the output file to contain "5":
<#= 2 + 3 #>
Source: http://msdn.microsoft.com/en-us/library/bb126478
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