Skip to content

Instantly share code, notes, and snippets.

@vietnt
Created August 25, 2011 10:58
Show Gist options
  • Save vietnt/1170434 to your computer and use it in GitHub Desktop.
Save vietnt/1170434 to your computer and use it in GitHub Desktop.
_new real-code
ITemplate Compile (string path, string id, string input, List<string> usings)
<- assembly.CreateInstance (typeName)
typeName = "Templates_Template_{0}_{1}".FormatWith (id, DateTime.Now.Ticks)
assembly = results.CompiledAssembly
results = provider.CompileAssemblyFromSource (options, code)
provider = new CSharpProvider
<- new Dictionary<string, string>
<- {"CompilerVersion", "v4.0"}
options = new CompilerParameters
.ReferenceAssemblies.Add
"System.dll"
"System.Core.dll"
"Microsoft.CSharp.dll"
path + "Zero.Web.dll"
path + "Zero.Core.dll"
.GenerateInMemory = true
code = inputs.Join("")
inputs = new[]
<- usingsStr
<- "@constant #1...."
<- "@constant #2...."
<- input
usingsStr = builder.ToString()
builder = new StringBuilder()
.AppendFormat ("using {0};", u)
u in usings
.Errors.HasErrors ?
throw new Exception(code + "\n Compiler error: " + b)
b = new StringBuilder()
.Append (e)
e in results.Errors
@vietnt
Copy link
Author

vietnt commented Aug 25, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment