نحوه استفاده از Text template ها در دات نت - قسمت دوم
نویسنده: افشین عباسپور
تاریخ: ۱۳۹۲/۱۱/۳۰ ۱۸:۳۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
<#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".txt" #> <# var T = DateTime.Now; #> The Time is : <#= T #> The Time is : <#= DateTime.Now #>
<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
using System;
using System.Text;
<# string ClassName = "DotnetTips"; #>
public class <#= ClassName + "_" + new MyTestClass().Str #>
{
}
<#+
public class MyTestClass
{
public string Str { get{return new DateTime().DayOfWeek.ToString() ;} }
}
#> using System;
using System.Text;
public class DotnetTips_Monday
{
} به عنوان یک مثال ساده دیگر برای فهم بیشتر به کد زیر جهت تولید Table در Html توجه کنید:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".html" #>
<html><body>
<table>
<# for (int i = 1; i <= 10; i++)
{ #>
<tr>
<td>Test name <#= i #> </td>
<td>Test value <#= i * i #> </td>
</tr>
<# } #>
</table>
</body></html>