Click or drag to resize

RoslynEvaluatorCompileCode Method (String, CompileInfo)

Evaluates (compiles) C# code (script). The C# code is a typical C# code containing a single or multiple class definition(s).

The method is identical to CompileCode(String) except that it allows specifying the destination assembly file.

Namespace:  CSScriptLib
Assembly:  CSScriptLib (in CSScriptLib.dll) Version: 1.3.2.0
Syntax
C#
public Assembly CompileCode(
	string scriptText,
	CompileInfo info = null
)

Parameters

scriptText
Type: SystemString
The C# script text.
info (Optional)
Type: CSScriptLibCompileInfo

Return Value

Type: Assembly
The compiled assembly.

Implements

IEvaluatorCompileCode(String, CompileInfo)
Examples
var info = new CompileInfo
{
    AssemblyFile = @"E:\temp\asm.dll"
};

Assembly asm = CSScript.Evaluator
                       .Cast<RoslynEvaluator>()
                       .CompileCode(@"using System;
                                      public class Script
                                      {
                                          public int Sum(int a, int b)
                                          {
                                              return a+b;
                                          }
                                      }",
                                      info);

dynamic script =  asm.CreateObject("*");
var result = script.Sum(7, 3);
See Also