I have a C# code generated dynamically using System.CodeDom.CodeCompileUnit
in runtime, I compile it using Microsoft.CSharp.CSharpCodeProvider
, What I want is to insert an already defined & initialized Variable (an ArrayList) to this string so I could use it before compile, How should I do this?
Asked
Active
Viewed 103 times
1

John Saunders
- 160,644
- 26
- 247
- 397

Vahid2023
- 863
- 3
- 11
- 33
-
You do know that `ArrrayList` is obsolete, right? – John Saunders May 23 '15 at 06:06
-
No , I didn't , Thanks for the heads-up – Vahid2023 May 23 '15 at 07:22
-
1It's been obsolete for ten years! Use `List
` instead. Use `List – John Saunders May 23 '15 at 07:24
1 Answers
2
You need to generate the code which creates this variable and fills it with the values you have. Or you can add an argument for one of the methods you generate and pass it at runtime. There's no magic method which will do it fo you.
CodeDom is incomplete, obsolete and outdated. Nowadays you should use T4 (if you want code as text) or Expressions and IL (if you want to execute dynamically generated code). If you use Expessions, inserting a variable is trivial. With T4, it'll take just a couple of lines of code, but will require doing it manually too.

Athari
- 33,702
- 16
- 105
- 146