0

I am experimenting with the CSharpCodeProvider .NET Code DOM class an I am able to compile an assembly and create an instance defined within the assembly, but I'm interested to know whether it is possible to 'inject' code or rather a class into a namespace within the executing assembly.

I could possibly work around the problem by compiling the code into an assembly file however I would like to do this in memory if possible.

svick
  • 236,525
  • 50
  • 385
  • 514
Drew R
  • 2,988
  • 3
  • 19
  • 27
  • 1
    Have you looked at anything like `Spring.Net` it handles `dependency Injection` – MethodMan Mar 29 '13 at 14:11
  • I would like to do this without resorting to any external frameworks libraries etc. Thanks though. – Drew R Mar 29 '13 at 14:14
  • 2
    You can't add code to an existing assembly. You *can* however, compile to an in-memory assembly (i.e. never write it to disk). Look at the `CompilerParameters.GenerateInMemory` property: http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilerparameters.generateinmemory.aspx – Jim Mischel Mar 29 '13 at 16:12
  • 1
    Assembly != namespace. You can add to the namespace after the fact, so to speak, but (probably) not an assembly, so Jim's suggestion should work for you. – 500 - Internal Server Error Mar 29 '13 at 16:20
  • Got there in the end, thanks. – Drew R Mar 29 '13 at 19:28

0 Answers0