Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用于在运行时生成字符串的文本模板(如Razor或T4)_C#_Silverlight_Razor_T4 - Fatal编程技术网

C# 用于在运行时生成字符串的文本模板(如Razor或T4)

C# 用于在运行时生成字符串的文本模板(如Razor或T4),c#,silverlight,razor,t4,C#,Silverlight,Razor,T4,网络上有没有工具可以用来从模板生成字符串,我正在寻找类似Razor的东西 字符串应该能够在运行时生成,并且不依赖于VisualStudio(如T4)。框架应该在Silverlight中工作 是一个满足要求但在Silverlight中不起作用的框架 提前谢谢。希望我理解您的要求,但我认为您也可以让T4在SL中工作。可以要求T4生成有时称为运行时模板的内容。我已经定义了我的模板(非常简单),并将其添加到我的Silverlight项目中 <# for (var iter = 0; ite

网络上有没有工具可以用来从模板生成字符串,我正在寻找类似Razor的东西

字符串应该能够在运行时生成,并且不依赖于VisualStudio(如T4)。框架应该在Silverlight中工作

是一个满足要求但在Silverlight中不起作用的框架


提前谢谢。

希望我理解您的要求,但我认为您也可以让T4在SL中工作。可以要求T4生成有时称为运行时模板的内容。我已经定义了我的模板(非常简单),并将其添加到我的Silverlight项目中

<#
    for (var iter = 0; iter < 10; ++iter)
    {
#>
    This is just a test: #<#=iter#>
<#
    }
#>
但在本例中,我喜欢生成生成该输出的代码,即运行时模板。为此,我将自定义工具切换为:TextTemplatingFilePreprocessor

现在,模板将生成生成该输出的代码。如果不使用hostspecific=true,则不会获得Visual Studio依赖项。通过使用成员变量扩展分部类并从模板文件引用它们,可以在运行时修改模板上的行为

Silverlight中的问题是Silverlight缺少类:System.CodeDom.Compiler.CompilerError和System.CodeDom.Compiler.CompilerErrorCollection

我通过创建自己的类来解决这个问题(就是为了这个目的):


检查一下当你说“仅适用于.NET”时,你的意思是它在Silverlight中不起作用?@FuleSnabel是的,你说得对,我纠正了这个问题
This is just a test: #0
This is just a test: #1
This is just a test: #2
This is just a test: #3
This is just a test: #4
This is just a test: #5
This is just a test: #6
This is just a test: #7
This is just a test: #8
This is just a test: #9
namespace System.CodeDom.Compiler
{
    public class CompilerError
    {
        public string ErrorText;
        public bool IsWarning;
    }

    public class CompilerErrorCollection : List<CompilerError>
    {

    }

}
var runtimeTemplate = new MyRuntimeTemplate();
string output = runtimeTemplate.TransformText();