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

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

Properties

AllowConcurrent

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

AllowOverflow

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

AllowUnsafe

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

GenerateInMemory

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

GetCachedAssembly

#
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.
public Assembly GetCachedAssembly { get; }

GetCachedErrors

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

GetCachedSemanticModels

#
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.
public SemanticModel[] GetCachedSemanticModels { get; }

GetCachedSyntaxTrees

#
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.
public SyntaxTree[] GetCachedSyntaxTrees { get; }

GetCachedWarnings

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

IncludeDebugData

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

Name

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

OutputPath

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

ReferenceCount

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

StandardAssemblies

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

StandardReferences

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

Methods

AddReferenceAssembly

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

CompileCSharpCode

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

CompileCSharpCode

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

CompileCSharpCode

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

CompileCSharpCode

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

CompileCSharpCode

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