Class CSharpScriptExecution

Class that can be used to execute code snippets or entire blocks of methods dynamically. Two methods are provided:

  • ExecuteCode - executes code and you can return a value * ExecuteMethod - lets you provide one or more method bodies to execute

Assemblies used for execution are cached and are reused for a given block of code provided.

System.Object
  Westwind.Scripting.CSharpScriptExecution
public class CSharpScriptExecution : object

Class Members

MemberDescription

Constructor

AddAssemblies

Adds a list of assemblies to the References collection.

public void AddAssemblies(String[] assemblies)

AddAssembly

Adds an assembly to be added to the compilation context.

public void AddAssembly(string assemblyDll)

public void AddAssembly(Type type)

AddDefaultReferencesAndNamespaces

Adds basic System assemblies and namespaces so basic operations work.

public void AddDefaultReferencesAndNamespaces()

AddNamespace

Adds a namespace to the referenced namespaces used at compile time.

public void AddNamespace(string nameSpace)

AddNamespaces

Adds a set of namespace to the referenced namespaces used at compile time.

public void AddNamespaces(String[] namespaces)

CompileAssembly

Compiles and runs the source code for a complete assembly.

public bool CompileAssembly(string source)

CompileClass

This method compiles a class and hands back a dynamic reference to that class that you can call members on.

public object CompileClass(string code)

CreateInstance

Creates an instance of the object specified by the GeneratedNamespace and GeneratedClassName.

Sets the ObjectInstance member which is returned

public object CreateInstance()

Evaluate

public object Evaluate(string code,     Object[] parameters)

ExecuteCode

public object ExecuteCode(string code,     Object[] parameters)

ExecuteCodeFromAssembly

Executes a method from an assembly that was previously compiled

public object ExecuteCodeFromAssembly(string code,     Assembly assembly,     Object[] parameters)

ExecuteMethod

Executes a complete method by wrapping it into a class.

public object ExecuteMethod(string code,     string methodName,     Object[] parameters)

InvokeMethod

Helper method to invoke a method on an object using Reflection

public object InvokeMethod(object instance,     string method,     Object[] parameters)

CompilerMode

CompilerResults

Compiler Results from the Compilation Process with detailed error information if an error occurs.

Error

Error flag that is set if an error occurred during the invoked method or script call

ErrorMessage

Error message if an error occurred during the invoked method or script call

GeneratedClassCode

Last generated code for this code snippet

GeneratedClassCodeWithLineNumbers

GeneratedClassName

GeneratedNamespace

LastException

Namespaces

List of additional namespaces to add to the script

ObjectInstance

Internal reference to the generated type that is to be invoked

OutputAssembly

Filename for the output assembly to generate. If empty the assembly is generated in memory (dynamic filename managed by the .NET runtime)

References

List of additional assembly references that are added to the compiler parameters in order to execute the script code.

SaveGeneratedCode

Determines whether GeneratedCode will be set with the source code for the full generated class

ThrowExceptions

If true throws exceptions rather than failing silently and returning error state. Default is false.

Requirements

Namespace: Westwind.Scripting
Assembly: westwind.scripting.dll

© West Wind Technologies, 1996-2019 • Updated: 02/25/19
Comment or report problem with topic