CodeCompiler

public sealed class CodeCompiler
Compiler utility class for C# and VB compilation. Although you can technically re-use the same CodeCompiler instance to compile consecutive bits of source, we highly recommend creating a new instance for every new compile job. This class leverages the Roslyn compiler behind the scenes.

Constructors

CodeCompiler

#
public CodeCompiler(string name)
Create a new code compiler with standard framework, RhinoCommon, Eto, Grasshopper, GrasshopperIO and MathNet assembly references.
name (string)Compilation project name. May be changed afterwards by setting the Name property.

Properties

AllowConcurrent

#
public bool AllowConcurrent { get; set; }
Gets or sets whether the compiler is allowed to run concurrently.

AllowOverflow

#
public bool AllowOverflow { get; set; }
Gets or sets whether integer over and underflow exceptions are handled.

AllowUnsafe

#
public bool AllowUnsafe { get; set; }
Gets or sets whether unsafe code blocks are allowed.

GenerateInMemory

#
public bool GenerateInMemory { get; }
Gets whether the assembly ought to be compiled in memory. This returns true when OutputPath is not set.

GetCachedAssembly

#
public Assembly GetCachedAssembly { get; }
Gets the assembly that was cached during the most recent compilation. This field may be null if no compilation has occured, if the most recent compilation failed, or it the most recent compilation generated an assembly on the disk.

GetCachedErrors

#
public CodeDiagnostic[] GetCachedErrors { get; }
Gets the collection of compiler warnings cached during the most recent compilation.

GetCachedSemanticModels

#
public SemanticModel[] GetCachedSemanticModels { get; }
Gets the collection of semantic models (one for every syntax tree) that were cached during the most recent compilation. This property may yield an empty array if no compilation has occured yet, or if the most recent compilation failed.

GetCachedSyntaxTrees

#
public SyntaxTree[] GetCachedSyntaxTrees { get; }
Gets the collection of syntax trees that were cached during the most recent compilation. This property may yield an empty array if no compilation has occured yet.

GetCachedWarnings

#
public CodeDiagnostic[] GetCachedWarnings { get; }
Gets the collection of compiler warnings cached during the most recent compilation.

IncludeDebugData

#
public bool IncludeDebugData { get; set; }
Gets or sets whether to generate debug level code.

Name

#
public string Name { get; set; }
Gets or sets the name of the assembly.

OutputPath

#
public string OutputPath { get; set; }
Gets or sets the assembly output path.

ReferenceCount

#
public int ReferenceCount { get; }
Gets the number of referenced assemblies.

StandardAssemblies

#
public static IEnumerable<string> StandardAssemblies { get; }
Enumerate over all assembly locations which are included by default in a compiled assembly.

StandardReferences

#
public static IEnumerable<MetadataReference> StandardReferences { get; }
Enumerate over all assembly references which are included by default in a compiled assembly.

Methods

AddReferenceAssembly

#
public bool AddReferenceAssembly(string path)
Add an assembly location to be referenced in the build.
path (string)Assembly file location.
True if assembly was added, false if it was already present.

CompileCSharpCode

#
public Assembly CompileCSharpCode(IEnumerable<string> code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
code (IEnumerable<string>)Code to compile.
warnings (out CodeDiagnostic[])Code warnings, if any.
errors (out CodeDiagnostic[])Code errors, if any.

CompileCSharpCode

#
public Assembly CompileCSharpCode(IEnumerable<SyntaxTree> code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
code (IEnumerable<SyntaxTree>)Code to compile.
warnings (out CodeDiagnostic[])Code warnings, if any.
errors (out CodeDiagnostic[])Code errors, if any.

CompileCSharpCode

#
public Assembly CompileCSharpCode(string code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
code (string)Code to compile.
warnings (out CodeDiagnostic[])Code warnings, if any.
errors (out CodeDiagnostic[])Code errors, if any.

CompileCSharpCode

#
public Assembly CompileCSharpCode(string code)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
code (string)Code to compile.

CompileCSharpCode

#
public Assembly CompileCSharpCode(SyntaxTree code, out CodeDiagnostic[] warnings, out CodeDiagnostic[] errors)
Compile C# code into an assembly. Note: this method *always* returns null if the assembly was written to disc rather than generated in memory.
code (SyntaxTree)Code to compile.
warnings (out CodeDiagnostic[])Code warnings, if any.
errors (out CodeDiagnostic[])Code errors, if any.