.net - Compiling dynamic code at runtime using T4 and C# -
the articles have read on t4 using texttemplatingfilepreprocessor show how dynamically generate code becomes part of project, , compiled project.
is possible use t4 generate code compiled @ runtime, outputted dll, , loaded , executed, said code having access usual visibility capabilities associated dll?
if so, please point me example.
i'm trying same thing generating dynamic dll using il, rather using c#.
edit
the specific case need straightforward. writing message router routes messages services. services may local or remote. declarative script compiled c#. dynamic part "is service local or remote?". output c# changed accordingly. style of routing different local / remote, hence dynamic nature.
this 1 example of need.
to this, need know 2 things:
- you can use run-time t4 template generate text @ runtime, including c# source code.
- you can use
csharpcodeprovidercompile assembly text @ runtime. or manually run csc.exe (the command-line c# compiler) on generated text, more complicated. (actuallycsharpcodeproviderbehind scenes.)
the code this:
var template = new runtimetexttemplate(); string code = template.transformtext(); var compiler = new csharpcodeprovider(); var result = compiler.compileassemblyfromsource( new compilerparameters { outputassembly = "assembly.dll" }, code);
Comments
Post a Comment