C# Класс Mono.CSharp.Evaluator

Evaluator: provides an API to evaluate C# statements and expressions dynamically.
This class exposes static methods to evaluate expressions in the current program. To initialize the evaluator with a number of compiler options call the Init(string[]args) method with a set of command line options that the compiler recognizes. To interrupt execution of a statement, you can invoke the Evaluator.Interrupt method.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
DescribeTypeExpressions bool

Открытые методы

Метод Описание
Compile ( string input ) : CompiledMethod

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.

Compile ( string input, CompiledMethod &compiled ) : string

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. If the return value of this function is null, this indicates that the parsing was complete. If the return value is a string it indicates that the input string was partial and that the invoking code should provide more code before the code can be successfully compiled. If you know that you will always get full expressions or statements and do not care about partial input, you can use the other Compile overload. On success, in addition to returning null, the compiled parameter will be set to the delegate that can be invoked to execute the code.

Evaluate ( string input ) : object

Evaluates and expression or statement and returns the result.

Evaluates the input string as a C# expression or statement and returns the value. This method will throw an exception if there is a syntax error, of if the provided input is not an expression but a statement.

Evaluate ( string input, object &result, bool &result_set ) : string

Evaluates and expression or statement and returns any result values.

Evaluates the input string as a C# expression or statement. If the input string is an expression the result will be stored in the result variable and the result_set variable will be set to true. It is necessary to use the result/result_set pair to identify when a result was set (for example, execution of user-provided input can be an expression, a statement or others, and result_set would only be set if the input was an expression. If the return value of this function is null, this indicates that the parsing was complete. If the return value is a string, it indicates that the input is partial and that the user should provide an updated string.

Evaluator ( CompilerSettings settings, Report report ) : System
GetCompletions ( string input, string &prefix ) : string[]
GetUsing ( ) : string
GetVars ( ) : string
Init ( ) : void
Interrupt ( ) : void

Interrupts the evaluation of an expression executing in Evaluate.

Use this method to interrupt long-running invocations.

LoadAssembly ( string file ) : void

Loads the given assembly and exposes the API to the user.

ReferenceAssembly ( Assembly a ) : void

Exposes the API of the given assembly to the Evaluator

Run ( string statement ) : bool

Executes the given expression or statement.

Executes the provided statement, returns true on success, false on parsing errors. Exceptions might be thrown by the called code.

Приватные методы

Метод Описание
CompileBlock ( Class host, Undo undo, Report Report ) : CompiledMethod
GetUsingList ( ) : ICollection
GetVarNames ( ) : string[]
LookupField ( string name ) : FieldInfo>.Tuple
ParseString ( ParseMode mode, string input, bool &partial_input ) : CSharpParser
Quote ( string s ) : string
Reset ( ) : void
ToplevelOrStatement ( Mono.CSharp.SeekableStreamReader seekable ) : InputKind

Описание методов

Compile() публичный метод

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
Результат CompiledMethod

Compile() публичный метод

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. If the return value of this function is null, this indicates that the parsing was complete. If the return value is a string it indicates that the input string was partial and that the invoking code should provide more code before the code can be successfully compiled. If you know that you will always get full expressions or statements and do not care about partial input, you can use the other Compile overload. On success, in addition to returning null, the compiled parameter will be set to the delegate that can be invoked to execute the code.
public Compile ( string input, CompiledMethod &compiled ) : string
input string
compiled CompiledMethod
Результат string

Evaluate() публичный метод

Evaluates and expression or statement and returns the result.
Evaluates the input string as a C# expression or statement and returns the value. This method will throw an exception if there is a syntax error, of if the provided input is not an expression but a statement.
public Evaluate ( string input ) : object
input string
Результат object

Evaluate() публичный метод

Evaluates and expression or statement and returns any result values.
Evaluates the input string as a C# expression or statement. If the input string is an expression the result will be stored in the result variable and the result_set variable will be set to true. It is necessary to use the result/result_set pair to identify when a result was set (for example, execution of user-provided input can be an expression, a statement or others, and result_set would only be set if the input was an expression. If the return value of this function is null, this indicates that the parsing was complete. If the return value is a string, it indicates that the input is partial and that the user should provide an updated string.
public Evaluate ( string input, object &result, bool &result_set ) : string
input string
result object
result_set bool
Результат string

Evaluator() публичный метод

public Evaluator ( CompilerSettings settings, Report report ) : System
settings CompilerSettings
report Report
Результат System

GetCompletions() публичный метод

public GetCompletions ( string input, string &prefix ) : string[]
input string
prefix string
Результат string[]

GetUsing() публичный метод

public GetUsing ( ) : string
Результат string

GetVars() публичный метод

public GetVars ( ) : string
Результат string

Init() публичный метод

public Init ( ) : void
Результат void

Interrupt() публичный метод

Interrupts the evaluation of an expression executing in Evaluate.
Use this method to interrupt long-running invocations.
public Interrupt ( ) : void
Результат void

LoadAssembly() публичный метод

Loads the given assembly and exposes the API to the user.
public LoadAssembly ( string file ) : void
file string
Результат void

ReferenceAssembly() публичный метод

Exposes the API of the given assembly to the Evaluator
public ReferenceAssembly ( Assembly a ) : void
a System.Reflection.Assembly
Результат void

Run() публичный метод

Executes the given expression or statement.
Executes the provided statement, returns true on success, false on parsing errors. Exceptions might be thrown by the called code.
public Run ( string statement ) : bool
statement string
Результат bool

Описание свойств

DescribeTypeExpressions публичное свойство

If true, turns type expressions into valid expressions and calls the describe method on it
public bool DescribeTypeExpressions
Результат bool