Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>CompileAssemblyFromDom compiles to a .cs file which is then run through the normal C# compiler.</p> <p>Example:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.CSharp; using System.CodeDom; using System.IO; using System.CodeDom.Compiler; using System.Reflection; namespace CodeDomQuestion { class Program { private static void Main(string[] args) { Program p = new Program(); p.dotest("C:\\fs.exe"); } public void dotest(string outputname) { CSharpCodeProvider cscProvider = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters(); cp.MainClass = null; cp.GenerateExecutable = true; cp.OutputAssembly = outputname; CodeNamespace ns = new CodeNamespace("StackOverflowd"); CodeTypeDeclaration type = new CodeTypeDeclaration(); type.IsClass = true; type.Name = "MainClass"; type.TypeAttributes = TypeAttributes.Public; ns.Types.Add(type); CodeMemberMethod cmm = new CodeMemberMethod(); cmm.Attributes = MemberAttributes.Static; cmm.Name = "Main"; cmm.Statements.Add(new CodeSnippetExpression("System.Console.WriteLine('f'zxcvv)")); type.Members.Add(cmm); CodeCompileUnit ccu = new CodeCompileUnit(); ccu.Namespaces.Add(ns); CompilerResults results = cscProvider.CompileAssemblyFromDom(cp, ccu); foreach (CompilerError err in results.Errors) Console.WriteLine(err.ErrorText + " - " + err.FileName + ":" + err.Line); Console.WriteLine(); } } } </code></pre> <p>which shows errors in a (now nonexistent) temp file:</p> <blockquote> <p>) expected - c:\Documents and Settings\jacob\Local Settings\Temp\x59n9yb-.0.cs:17</p> <p>; expected - c:\Documents and Settings\jacob\Local Settings\Temp\x59n9yb-.0.cs:17</p> <p>Invalid expression term ')' - c:\Documents and Settings\jacob\Local Settings\Tem p\x59n9yb-.0.cs:17</p> </blockquote> <p>So I guess the answer is "no"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload