It would be nice if Razor would implement @"..."@ or @'...'@ as alias for <text>...</text> . I added this razorengine.codeplex-Issue as a request to improve. If you plan to use razor as codegenerator please upvote it at razorengine.codeplex-Issue
Edit: as @Epitka suggested, we can use @: in place of a single line text tag:
using System;
namespace @Model.UserNamespace
{
class Program
{
static void Main(string[] args)
{
@for(int i = 0; i < 3; i++){
@:Debug.WriteLine("hello @i " + @Model.UserNamespace);
}
}
}
}
发布评论
评论(3)
我第一次尝试 razor.dll 版本 2.1 .4039.23635 比我预期的要容易得多
这是一个小型工作演示
codegenerator
template 看起来像这样
请注意
元素阻止 razor 解释Debug.WriteLine
输出 是
如果 Razor 能够实现
@"..."@
或那就太好了>@'...'@
作为...
的别名。我添加了这个 razorengine.codeplex-Issue 作为改进请求。如果您计划使用 razor 作为代码生成器,请在 razorengine.codeplex-Issue 上投票编辑:as @ Epitka建议,我们可以使用
@:
代替单行文本标签:My first try with razor.dll version 2.1.4039.23635 was much easier than i expected
Here is a small working demo
The codegenerator
The template looks like this
Note the
<text>
element that prevents razor from interpreting theDebug.WriteLine
The output is
It would be nice if Razor would implement
@"..."@
or@'...'@
as alias for<text>...</text>
. I added this razorengine.codeplex-Issue as a request to improve. If you plan to use razor as codegenerator please upvote it at razorengine.codeplex-IssueEdit: as @Epitka suggested, we can use
@:
in place of a single line text tag:您当然可以使用 Razor 生成 C# 代码,但它并不是真正为非 XML 类语言设计的。你必须有很多标签。
You certainly could use Razor to generate C# code, but it's not really designed for non-XML-like languages. You'd have to have a lot of <text> tags.
您可以像 T4 模板一样使用 razor 来生成任何类型的文本。请参阅这篇博文。
http://weblogs.asp .net/mikaelsoderstrom/archive/2010/08/03/use-razor-for-t4-templates.aspx
You can use razor just like T4 templates to generate any type of text. See this blog post.
http://weblogs.asp.net/mikaelsoderstrom/archive/2010/08/03/use-razor-for-t4-templates.aspx