I hope I understand what you asked for, but I would say that you can get T4 to work in SL as well. T4 can be asked to generate what are sometimes called runtime patterns. I defined my template (very simple) and added it to my Silverlight project.
<# for (var iter = 0; iter < 10; ++iter) { #> This is just a test: #<#=iter#> <# } #>
Usually it generates this output:
This is just a test:
But in this case, I like to generate code that generates this output, i.e. runtime pattern. To do this, I will switch my own tool: TextTemplatingFilePreprocessor
Now the template generates code that generates this output. If you avoid hostpecific = true, you are not getting Visual Studio dependencies. By extending a partial class with member variables and referencing them from a template file, you can change the behavior of the template at run time.
The problem with Silverlight is that there are no classes in Silverlight: System.CodeDom.Compiler.CompilerError and System.CodeDom.Compiler.CompilerErrorCollection.
I worked on this by creating my own classes for this (just for this purpose):
namespace System.CodeDom.Compiler { public class CompilerError { public string ErrorText; public bool IsWarning; } public class CompilerErrorCollection : List<CompilerError> { } }
Now my template compiles, and I just like this from my Silverlight application to create the output:
var runtimeTemplate = new MyRuntimeTemplate(); string output = runtimeTemplate.TransformText();
source share