Mono.CSharp.Evaluator.Compile C# (CSharp) Method

Compile() public method

Compiles the input string and returns a delegate that represents the compiled code.
Compiles the input string as a C# expression or statement, unlike the Evaluate method, the resulting delegate can be invoked multiple times without incurring in the compilation overhead. This method can only deal with fully formed input strings and does not provide a completion mechanism. If you must deal with partial input (for example for interactive use) use the other overload. On success, a delegate is returned that can be used to invoke the method.
public Compile ( string input ) : CompiledMethod
input string
return CompiledMethod
        public CompiledMethod Compile(string input)
        {
            CompiledMethod compiled;

            // Ignore partial inputs
            if (Compile (input, out compiled) != null){
                // Error, the input was partial.
                return null;
            }

            // Either null (on error) or the compiled method.
            return compiled;
        }

Same methods

Evaluator::Compile ( string input, CompiledMethod &compiled ) : string

Usage Example

Example #1
0
    static void MonoCSharp_Test()
    {
        string className = GetClass();
        string code      = GetCode(className);

        evaluator.Compile(code);

        dynamic script = evaluator.Evaluate("new " + className + "();");

        int result = script.Sum(1, 2);
    }
All Usage Examples Of Mono.CSharp.Evaluator::Compile