c# - Pass an array of bytes to T4 Template code into another array of same type -


i'm using t4template , codedom create assembly using following code:

compilerparameters params = new compilerparameters();             params.generateexecutable = true;             params.referencedassemblies.add("system.dll");             params.outputassembly = "myfile.exe";              runtimetexttemplate1 rtt = new runtimetexttemplate1();             string source = rtt.transformtext();              compilerresults create = new csharpcodeprovider().compileassemblyfromsource(params, source); 

the template looks ( moment ) :

<#@ template language="c#" #> namespace application {   class program   {      static void main()      {        byte[] buffer = new byte[1024];        //and code creating file bytes in buffer.      }   } } 

in main application have byte array contains bytes of application , these bytes loaded array @ runtime.

my question :

  • how can pass array of bytes contains data(bytes) t4template in ( byte[] buffer = new byte[1024]; ) when assembly created code written in template,the array should contain bytes.

personally, i'd prefer pass data generated code @ runtime, if need embed within generated assembly, this:

add class feature block byte array parameter member in it, you'll able set runtime template , access in template. following

<#@ template language="c#" #> namespace application {   class program   {      static void main()      {        byte[] buffer = new byte[1024] { <#= buffervalue.select(b => "0x" + b.tostring("x2")).aggregate((f, s) => f + ", " + s) #> };        //and code creating file bytes in buffer.      }   } } <#+  public byte[] buffervalue { get; set; }   #> 

then set rtt.buffervalue array before invoking template.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -