CSScriptLibrary Executes "public static void Main(..)" of assembly in a separate domain. Invokes static method 'Main' from the assembly. AppDomain event handler. This handler will be called if CLR cannot resolve referenced local assemblies Very light parser for C# code. The main purpose of it is to be very fast and reliable. It only extracts code information relative to the CS-Script. Class to hold the script information on what pre- or post-execution script needs to be executed. pre- and post-script CS-Script command format: //css_prescript file([arg0][, arg1]..[,arg2])[,ignore]; //file - script file (extension is optional) //arg0..N - script string arguments; If $this is specified as arg0..N it will be replaced with the parent script full name at execution time. Creates an instance of CmdScriptInfo. CS-Script pre- or post-script directive If set to true the 'statement' is a pre-script otherwise it is a post-script. The file name of the main script. Script file and it's arguments. If set to 'true' the CmdScriptInfo describes the pre-script, otherwise it is for the post-script. If set to 'true' parent script will be aborted on pre/post-script error, otherwise the error will be ignored. Class to hold the script initialization information. The boolean flag indicating if CoInitializeSecurity (with default parameters) should be called at the start of the script execution. The RpcImpLevel of CoInitializeSecurity arguments The EoAuthnCap of CoInitializeSecurity arguments Initializes a new instance of the class. The original argument statement of the //css_init directive. Class to hold the script importing information, which actually controls how script is imported. When importing/referencing dependencies with '//css_include', '//css_import' or '//css_reference' you can use relative path. Resolving relative path is typically done with respect to the current directory. The only exception is any path that starts with a single dot ('.') prefix, which triggers the conversion of the path into the absolute path with respect to the location of the file containing the import directive. Set to true if you want to convert all relative paths into the absolute path, not only the ones with a single dot ('.') prefix. By default it is set to false unless overwritten via the global settings. Creates an instance of ImportInfo. CS-Script import directive (//css_import...) string. name of the parent (primary) script file. Creates an instance of ImportInfo. CS-Script import directive (//css_import...) string. name of the parent (primary) script file. The context string to be injected in the exception message if raised. The file to be imported. The original name of the file to be imported. The name of the script containing the import statement. Renaming instructions (old_name vs. new_name) If set to 'true' "static...Main" in the imported script is not renamed. Creates an instance of CSharpParser. C# code string Creates an instance of CSharpParser. C# script (code or file). If set to 'true' the script is a file, otherwise it is a C# code. Loads and parses the file the file. The script. Parser object containing parsing result. Creates an instance of CSharpParser. C# script (code or file). If set to 'true' the script is a file, otherwise it is a C# code. Additional C# script directives to search. The search result is stored in CSharpParser.CustomDirectives. Creates an instance of CSharpParser. C# script (code or file). If set to 'true' the script is a file, otherwise it is a C# code. Additional C# script directives to search. The search result is stored in CSharpParser.CustomDirectives. Search directories for resolving wild card paths in //css_inc and //css_imp The result of search for additional C# script directives to search (directive vs. value). Global flag to forcefully suppress any C# code analyzes. This flag effectively disables all CS-Script assembly and script probing and most likely some other functionality. You may ever want to suppress code analysis only for profiling purposes or during performance tuning. Global flag to forcefully suppress any C# code analyzes. This flag effectively disables all CS-Script assembly and script probing and most likely some other functionality. You may ever want to suppress code analysis only for profiling purposes or during performance tuning. Parses the C# code. C# script (code or file). If set to 'true' the script is a file, otherwise it is a C# code. Additional C# script directives to search. The search result is stored in CSharpParser.CustomDirectives. Search directories for resolving wild card paths in //css_inc and //css_imp Renames namespaces according renaming instructions. Renaming instructions (old_name vs. new_name). /// If set to 'true' "static...Main" in the imported script is not renamed. Embedded script arguments. The both script and engine arguments are allowed except "/noconfig" engine command line switch. Embedded compiler options. Embedded compiler options. Precompilers. References to the external assemblies and namespaces. References to the external assemblies. Names of namespaces to be ignored by namespace-to-assembly resolver. Additional search directories (for script and assembly probing). References to the resource files. References to the namespaces. References to the NuGet packages. C# scripts to be imported. Pre- and post-execution scripts. Script initialization directives. Apartment state of the script. Gets the `auto-class` decoration mode value. Script C# raw code. Script C# code after namespace renaming. Enables omitting closing character (";") for CS-Script directives (e.g. "//css_ref System.Xml.dll" instead of "//css_ref System.Xml.dll;"). Escapes the CS-Script directive (e.g. //css_*) delimiters. All //css_* directives should escape any internal CS-Script delimiters by doubling the delimiter character. For example //css_include for 'script(today).cs' should escape brackets as they are the directive delimiters. The correct syntax would be as follows '//css_include script((today)).cs;' The delimiters characters are ';,(){}'. However you should check for the accurate list of all delimiters. The text to be processed. Replaces the user escaped delimiters with internal escaping.

"{char}{char}" -> "\u{((int)c).ToString("x4")}"

"((" -> "\u0028"

The text.
Unescapes the CS-Script directive (e.g. //css_*) delimiters. All //css_* directives should escape any internal CS-Script delimiters by doubling the delimiter character. For example //css_include for 'script(today).cs' should escape brackets as they are the directive delimiters. The correct syntax would be as follows '//css_include script((today)).cs;' The delimiters characters are ';,(){}'. However you should check for the accurate list of all delimiters. The text to be processed. The //css_* directive delimiters. All //css_* directives should escape any internal CS-Script delimiters by doubling the delimiter character. For example //css_include for 'script(today).cs' should escape brackets as they are the directive delimiters. The correct syntax would be as follows '//css_include script((today)).cs;' Delegate implementing source file probing algorithm. The file. The extra dirs. if set to true [throw on error]. Delegate implementing assembly file probing algorithm. The file. The extra dirs. CSExecutor is an class that implements execution of *.cs files. Force caught exceptions to be re-thrown. The main entry point for the application. Returns custom application config file. Dummy 'print' to suppress displaying application messages. This method implements compiling and execution of the script. This method implements compiling and execution of the script. Compiles C# script file into assembly. C# Script arguments array (sub array of application arguments array). Callback to print application messages to appropriate output. Container for parsed command line arguments Flag to force to rethrow critical exceptions Constructor Constructor Checks/returns if compiled C# script file (ScriptName + ".compiled") available and valid. Compiles C# script file. Returns the name of the temporary file in the CSSCRIPT subfolder of Path.GetTempPath(). Temporary file name. Returns the name of the temporary folder in the CSSCRIPT subfolder of Path.GetTempPath(). Under certain circumstances it may be desirable to the use the alternative location for the CS-Script temporary files. In such cases use SetScriptTempDir() to set the alternative location. Temporary directory name. Sets the location for the CS-Script temporary files directory. The path for the temporary directory. Generates the name of the cache directory for the specified script file. Script file name. Cache directory name. Contains the name of the temporary cache folder in the CSSCRIPT subfolder of Path.GetTempPath(). The cache folder is specific for every script file. Generates the name of the temporary cache folder in the CSSCRIPT subfolder of Path.GetTempPath(). The cache folder is specific for every script file. script file Prints Help info. Prints CS-Script specific C# syntax help info. Show sample C# script file. Show sample precompiler C# script file. Performs the cache operations and shows the operation output. The command. Creates the default config file in the CurrentDirectory. Prints the config file default content. Show CS-Script version information. The exception that is thrown when an incvalid CS-Script directive is encountered. Initializes a new instance of the class. The message. The exception that is thrown when a the script CLI error occurs. The exception that is thrown when a the script compiler error occurs. Initializes a new instance of the class. Initializes a new instance of the class. The object that holds the serialized object data. The contextual information about the source or destination. Initializes a new instance of the class. The message. Gets or sets the error count associated with the last script compilation. The error count. Creates the CompilerException instance from the specified compiler errors. The compiler errors. if set to true hide compiler warnings. if set to true all references to the path of the derived auto-generated files (e.g. errors in the decorated classless scripts) will be replaced with the path of the original files (e.g. classless script itself). Indicates synchronization model used to for controlling concurrency when the same script file is executed by multiple processes. Simple model. The script engine doesn't start the timestamp validation and the script compilation until another engine validating finishes its job. Note: the compilation may be skipped if caching is enabled and the validation reviles that the previous compilation (cache) is still up to date. Due to the limited choices with the system wide named synchronization objects on Linux Standard is the only available synchronization model on Linux. And it is just happens to be a good default choice for Windows as well. A legacy synchronization model available on Windows only. While it can be beneficial in the intense concurrent "border line" scenarios, its practical value very limited. No concurrency control is done by the script engine. All synchronization is the responsibility of the hosting environment. Application specific runtime settings Based on "maettu-this" proposal https://github.com/oleg-shilo/cs-script/issues/78 His `SplitLexicallyWithoutTakingNewLineIntoAccount` is taken/used practically without any change. COM HR checker: just to make code more compact; IAssemblyCache; COM import IAssemblyName; COM import IAssemblyEnum; COM import AssemblyCommitFlags; Used by COM imported calls AssemblyCacheFlags; Used by COM imported calls AssemblyCacheUninstallDisposition; Used by COM imported calls CreateAssemblyNameObjectFlags; Used by COM imported calls AssemblyNameDisplayFlags; Used by COM imported calls InstallReference + struct initialization; Used by COM imported calls AssemblyInfo; Used by COM imported calls InstallReferenceGuid; Used by COM imported calls Helper class for IAssemblyCache Helper class for IAssemblyEnum Gets the package compatible library. Similar to `GetCompatibleTargetFramework` but relies on file structure The package. Gets the single package library dirs. The package. The root dir. This class is a container for information related to the script pre-compilation. It is used to pass an input information from the script engine to the precompiler instance as well as to pass back to the script engine some output information (e.g. added referenced assemblies) . Collection of the referenced assemblies to be added to the process script referenced assemblies. You may want to add new items to the referenced assemblies because of the pre-compilation logic (e.g. some code using assemblies not referenced by the primary script is injected in the script). Collection of the new dependency items (files). Dependency files are checked before the script execution in order to understand if the script should be recompiled or it can be loaded from the cache. If any of the dependency files is changed since the last script execution the script engine will recompile the script. In the simple execution scenarios the script file is a dependency file. Collection of the new 'include' items (dependency source files). Collection of the assembly and script probing directories to be added to the process search directories. You may want to add new items to the process search directories because of the pre-compilation logic. Additional compiler options to be passed to the script compiler Collection of the process assembly and script probing directories. AutoclassGenerator to be used by external applications for generating the auto-class from the classless scripts Processes the specified code. The code. The injection position. Length of the injection. Processes the specified code. The code. The position. The console encoding to be set for at the script initialization. Class that holds all information about the execution context (probing directories and dependencies) of a script. Primary script that defines the project. List of all C# sources defined by the project. This includes the primary script itself and all other scripts files the imported/included by the primary script. List of assemblies the script of the project is referencing. List of search folders where CS-Script does probing for imported/included scripts and assemblies. Generates the top level view project for a given script. Note this method uses the same algorithm as CS-Script executor but it deliberately doesn't include cached directories and auto-generated files. This method is to be used by IDs and tools. The script. Gets the CSS configuration. Used by ST3 Syntaxer cls Settings is an class that holds CS-Script application settings. Command to be executed to perform custom cleanup. If this value is empty automatic cleanup of all temporary files will occurs after the script execution. This implies that the script has to be executed in the separate AppDomain and some performance penalty will be incurred. Setting this value to the command for custom cleanup application (e.g. csc.exe cleanTemp.cs) will force the script engine to execute script in the 'current' AppDomain what will improve performance. Returns value of the CleanupShellCommand (with expanding environment variables). shell command string This value indicates frequency of the custom cleanup operation. It has affect only if CleanupShellCommand is not empty. Location of alternative code provider assembly. If set it forces script engine to use an alternative code compiler. Gets or sets the path to the Roslyn directory. This setting is used to redirect Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll to the custom location of the Roslyn compilers (e.g. /usr/lib/mono/4.5). The Roslyn directory. When importing dependency scripts with '//css_include' or '//css_import' you can use relative path. Resolving relative path is typically done with respect to the current directory. The only exception is any path that starts with a single dot ('.') prefix, which triggers the conversion of the path into the absolute path with respect to the location of the file containing the import directive. Set to true if you want to convert all relative paths into the absolute path, not only the ones with a single dot ('.') prefix. Returns value of the UseAlternativeCompiler (with expanding environment variables). Path string Location of PostProcessor assembly. If set it forces script engine to pass compiled script through PostProcessor before the execution. Returns value of the UsePostProcessor (with expanding environment variables). Path string DefaultApartmentState is an ApartmemntState, which will be used at run-time if none specified in the code with COM threading model attributes. Default command-line arguments. For example if "/dbg" is specified all scripts will be compiled in debug mode regardless if the user specified "/dbg" when a particular script is launched. Gets or sets a value indicating whether script assembly attribute should be injected. The AssemblyDecription attribute contains the original location of the script file the assembly being compiled from./ true if the attribute should be injected; otherwise, false. Gets or sets a value indicating whether to enable Python-like print methods (e.g. dbg.print(DateTime.Now)). true if print methods are enabled; otherwise, false. Gets or sets a value indicating whether references to the auto-generated files should be resolved. If this flag is set the all references in the compile errors text to the path of the derived auto-generated files (e.g. errors in the decorated classless scripts) will be replaced with the path of the original file(s) (e.g. classless script itself). true if preferences needs to be resolved; otherwise, false. Enables omitting closing character (";") for CS-Script directives (e.g. "//css_ref System.Xml.dll" instead of "//css_ref System.Xml.dll;"). Encoding of he Console Output. Applicable for console applications script engine only. Gets or sets a value indicating whether to enforce timestamping the compiled script assembly. Some reports indicated that changing assembly timestamp can affect CLR caching (shadow copying) due to some unknown/undocumented CLR feature(s). Thus script caching algorithm has been changed to avoid using the compiled assembly LastModifiedTime file-attribute for storing the script timestamp. Currently caching algorithm uses injected metadata instead. If for whatever reason the old behaver is preferred you can always enable it by either setting to true or by setting CSS_LEGACY_TIMESTAMP_CAHING environment variable to "true". Triggered by issue #61: https://github.com/oleg-shilo/cs-script/issues/61 true if to suppress timestamping; otherwise, false. Gets or sets the custom CS-Script temporary directory. The custom temporary directory. Specifies the .NET Framework version that the script is compiled against. This option can have the following values: v2.0 v3.0 v3.5 v4.0 Specifies the .NET Framework version that the script is compiled against. This option can have the following values: v2.0 v3.0 v3.5 v4.0 List of assembly names to be automatically referenced by the script. The items must be separated by coma or semicolon. Specifying .dll extension (e.g. System.Core.dll) is optional. Assembly can contain expandable environment variables. Returns value of the DefaultRefAssemblies (with expanding environment variables). List of assembly names List of directories to be used to search (probing) for referenced assemblies and script files. This setting is similar to the system environment variable PATH. Add search directory to the search (probing) path Settings.SearchDirs. For example if Settings.SearchDirs = "c:\scripts" then after call Settings.AddSearchDir("c:\temp") Settings.SearchDirs is "c:\scripts;c:\temp" Directory path. The value, which indicates if auto-generated files (if any) should be hidden in the temporary directory. Path to the precompiler script/assembly (see documentation for details). You can specify multiple recompiles separating them by semicolon. Gets or sets a value indicating whether custom string hashing algorithm should be used. String hashing is used by the script engine for allocating temporary and cached paths. However default string hashing is platform dependent (x32 vs. x64) what makes impossible truly deterministic string hashing. This in turns complicates the integration of the CS-Script infrastructure with the third-party applications (e.g. Notepad++ CS-Script plugin). To overcome this problem CS-Script uses custom string hashing algorithm (default setting). Though the native .NET hashing can be enabled if desired by setting CustomHashing to false. true if custom hashing is in use; otherwise, false. Enum for possible hide auto-generated files scenarios Note: when HideAll is used it is responsibility of the pre/post script to implement actual hiding. Do not hide auto-generated files. Hide the most of the auto-generated (cache and "imported") files. Hide all auto-generated files including the files generated by pre/post scripts. Boolean flag that indicates how much error details to be reported should error occur. false - Top level exception will be reported true - Whole exception stack will be reported Gets or sets a value indicating whether Optimistic Concurrency model should be used when executing scripts from the host application. If set to false the script loading (not the execution) is globally thread-safe. If set to true the script loading is thread-safe only among loading operations for the same script file. The default value is true. true if Optimistic Concurrency model otherwise, false. Gets or sets a value indicating whether auto-class decoration should allow C# 6 specific syntax. If it does the statement "using static dbg;" will be injected at the start of the auto-class definition thus the entry script may invoke static methods for object inspection with dbg class without specifying the class name (e.g. "print(DateTime.Now);"). true if decorate auto-class as C# 6; otherwise, false. Boolean flag that indicates if compiler warnings should be included in script compilation output. false - warnings will be displayed true - warnings will not be displayed Boolean flag that indicates the script assembly is to be loaded by CLR as an in-memory byte stream instead of the file. This setting can be useful when you need to prevent script assembly (compiled script) from locking by CLR during the execution. false - script assembly will be loaded as a file. It is an equivalent of Assembly.LoadFrom(string assemblyFile). true - script assembly will be loaded as a file. It is an equivalent of Assembly.Load(byte[] rawAssembly) Note: some undesired side effects can be triggered by having assemblies with Assembly.Location being empty. For example Interface Alignment any not work with such assemblies as it relies on CLR compiling services that typically require assembly Location member being populated with the valid path. Gets or sets the concurrency control model. The concurrency control. Serializes instance of Settings. Saves CS-Script application settings to a file. File name of the settings file Loads CS-Script application settings from a file. Default settings object is returned if it cannot be loaded from the file. File name of the XML file Setting object deserialized from the XML file Gets the default configuration file path. It is a "css_config.xml" file located in the same directory where the assembly being executed is (e.g. cscs.exe). Note, when running under Mono the "css_config.mono.xml" file will have higher precedence than "css_config.xml". This way you can have Mono specific settings without affecting the settings for non-Mono runtimes. The default configuration file location. Returns null if the file is not found. Loads CS-Script application settings from the default config file (css_config.xml in the cscs.exe/csws.exe folder). Create and return default settings object if it cannot be loaded from the file. Setting object deserialized from the XML file Loads CS-Script application settings from a file. File name of the XML file Create and return default settings object if it cannot be loaded from the file. Setting object deserialized from the XML file Class containing all information about script compilation context and the compilation result. The script file that the CompilingInfo is associated with. The script parsing context containing the all CS-Script specific compilation/parsing info (e.g. probing directories, NuGet packages, compiled sources). The script compilation result. The compilation context object that contain all information about the script compilation input (referenced assemblies, compiler symbols). Waits for file idle. The file. The delay. true if the wait is successful. Adds compiler options to the CompilerParameters in a manner that it does separate every option by the space character Compiles ResX file into .resources Parses application (script engine) arguments. Arguments Script executor instance Index of the first script argument. The MetaDataItems class contains information about script dependencies (referenced local assemblies and imported scripts) and compiler options. This information is required when scripts are executed in a 'cached' mode (/c switch). On the base of this information the script engine will compile new version of .compiled assembly if any of it's dependencies is changed. This is required even for referenced local assemblies as it is possible that they are a strongly named assemblies (recompiling is required for any compiled client of the strongly named assembly in case this assembly is changed). The perfect place to store the dependencies info (custom meta data) is the assembly resources. However if we do so such assemblies would have to be loaded in order to read their resources. It is not acceptable as after loading assembly cannot be unloaded. Also assembly loading can significantly compromise performance. That is why custom meta data is just physically appended to the file. This is a valid approach because such assembly is not to be distributed anywhere but to stay always on the PC and play the role of the temporary data for the script engine. Note: A .dll assembly is always compiled and linked in a normal way without any custom meta data attached. Helper for retrieving currently installed .NET version Returns the exact full version of the installed .NET 4.5 This class implements access to the CS-Script global configuration settings. Generates the name of the cache directory for the specified script file. Script file name. Cache directory name. Saves code to the script file in the dedicated CS-Script temporary files location. You do not have to delete the script file after the execution. It will be deleted as part of the periodical automatic CS-Script maintenance. The script file content. Name of the created temporary script file. Generates the script file path in the dedicated CS-Script temporary files location. You do not have to delete such file after the execution. It will be deleted as part of the periodical automatic CS-Script maintenance. Name of the temporary script file. Sets the location for the CS-Script temporary files directory. The path for the temporary directory. Gets the location of the CS-Script temporary files directory. The full name of the script file being executed. The full name of the primary script file being executed. Usually it is the same file as ScriptFile. However these fields are different if analyzed from the pre/post-script. Repository for application specific data Enables access to objects across application domain boundaries in applications that support Remoting, giving them infinite lease time by setting to . var code = @"using System; public class Script : MarshalByRefObjectWithInfiniteLifetime { public void Hello(string greeting) { Console.WriteLine(greeting); } }"; using (var helper = new AsmHelper(CSScript.CompileCode(code), null, deleteOnExit: true)) { IScript script = helper.CreateAndAlignToInterface<IScript>("*"); script.Hello("Hi there..."); } The script engine mechanism is not a real inter-process communication. It does use remoting, but within a single process. So it is acceptable to switch off the timeout mechanism. When the hosting application is terminated, all objects will be finalized anyway. Without the modification, if there is no interaction between script and host for more than 5 minutes (the default lease time for .NET Remoting), a may be thrown, stating: /.rem' has been disconnected or does not exist at the server.]]> Obtains a lifetime service object to control the lifetime policy for this instance. Class for resolving assembly name to assembly file File to be excluded from assembly search Gets or sets a value indicating whether the assembly probing results should be cached. Default value is false; Caching means that during the probing if the assembly is not found in one of the probing directories this directory will not be checked again if the same assembly is to be resolved in the future. This setting is to be used with the caution. While it can bring some performance benefits when the list of probing directories is large it also may be wrong to assume that if the assembly in not found in a particular directory it still will not be there if the probing is repeated. true if probing results should be cached; otherwise, false. Resolves assembly name to assembly file. Loads assembly file to the current AppDomain. The name of assembly The name of directory where local assemblies are expected to be if set to true [throw exceptions]. loaded assembly Determines whether the string is a legal path token. The name. true if the string is a legal path token; otherwise, false. Resolves namespace/assembly(file) name into array of assembly locations (local and GAC ones). 'namespace'/assembly(file) name Assembly search directories If the default implementation isn't suitable then you can set CSScript.FindAssemblyAlgorithm to the alternative implementation of the probing algorithm. collection of assembly file names where namespace is implemented Resolves namespace into array of local assembly locations. (Currently it returns only one assembly location but in future it can be extended to collect all assemblies with the same namespace) namespace/assembly name directory collection of assembly file names where namespace is implemented Resolves namespace into array of global assembly (GAC) locations. 'namespace' name collection of assembly file names where namespace is implemented Search for namespace into local assembly file. ParsingParams is an class that holds parsing parameters (parameters that controls how file is to be parsed). At this moment they are namespace renaming rules only. Compare() is to be used to help with implementation of IComparer for sorting operations. Class which is a placeholder for general information of the script file Constructor ImportInfo object containing the information how the script file should be parsed. Class that implements parsing the single C# script file Searches for script file by given script name. Calls ResolveFile(string fileName, string[] extraDirs, bool throwOnError) with throwOnError flag set to true. The resolve file algorithm, The default algorithm searches for script file by given script name. Search order: 1. Current directory 2. extraDirs (usually %CSSCRIPT_DIR%\Lib and ExtraLibDirectory) 3. PATH Also fixes file name if user did not provide extension for script file (assuming .cs extension) Searches for script file by given script name. Search order: 1. Current directory 2. extraDirs (usually %CSSCRIPT_DIR%\Lib and ExtraLibDirectory) 3. PATH Also fixes file name if user did not provide extension for script file (assuming .cs extension) If the default implementation isn't suitable then you can set FileParser.ResolveFilesAlgorithm to the alternative implementation of the probing algorithm. Class that implements parsing the single C# Script file Implementation of the IComparer for sorting operations of collections of FileParser instances Information about the script parsing result. The packages referenced from the script with `//css_nuget` directive The referenced resources referenced from the script with `//css_res` directive The referenced assemblies referenced from the script with `//css_ref` directive The namespaces imported with C# `using` directive The namespaces that are marked as "to ignore" with `//css_ignore_namespace` directive The compiler options specified with `//css_co` directive The directories specified with `//css_dir` directive The precompilers specified with `//css_pc` directive All files that need to be compiled as part of the script execution. The time of parsing. Class that manages parsing the main and all imported (if any) C# Script files Gets the script parsing context. This object is effectively a parsing result. Processes the imported script. Processing involves lookup for 'static Main' and renaming it so it does not interfere with the 'static Main' of the primary script. After renaming is done the new content is saved in the CS-Script cache and the new file location is returned. The saved file can be used late as an "included script". This technique can be from 'precompiler' scripts. If the script file does not require renaming (static Main is not present) the method returns the original script file location. The script file. ApartmentState of a script during the execution (default: ApartmentState.Unknown) Collection of the files to be compiled (including dependent scripts) Collection of the imported files (dependent scripts) Collection of resource files referenced from code Collection of compiler options Precompilers specified in the primary script file. Collection of namespaces referenced from code (including those referenced in dependant scripts) Collection of namespaces, which if found in code, should not be resolved into referenced assembly. Resolves the NuGet packages into assemblies to be referenced by the script. If the package was never installed/downloaded yet CS-Script runtime will try to download it. CS-Script will also analyze the installed package structure in try to reference compatible assemblies from the package. if set to true suppresses downloading the NuGet package. Suppressing can be useful for the quick 'referencing' assessment. Collection of the referenced assembly files. Collection of the NuGet packages Collection of referenced assemblies. All assemblies are referenced either from command-line, code or resolved from referenced namespaces. Constructor. Script file name Constructor. Script file name Extra ScriptLibrary directory Constructor. Script file name Extra ScriptLibrary directory(s) flag to indicate if the file parsing/processing error should raise an exception The path of the parsed script. Initialization of ScriptParser instance Script file name Extra ScriptLibrary directory(s) Saves all imported scripts int temporary location. Collection of the saved imported scrips file names Deletes imported scripts as a cleanup operation CS-Script SearchDirectories specified in the parsed script or its dependent scripts. Aggregates the references from the script and its imported scripts. It is a logical equivalent of CSExecutor.AggregateReferencedAssemblies but optimized for later .NET versions (e.g LINQ) and completely decoupled. Thus it has no dependencies on internal state (e.g. settings, options.shareHostAssemblies). It is the method to call for generating list of ref asms as part of the project info. The search dirs. The default ref asms. The default namespaces. Delegate which is used as a return type for AsmHelper.GetMethodInvoker(). AsmHelper.GetMethodInvoker() allows obtaining dynamic method delegate emitted on the base of the MethodInfo (from the compiled script type). Instance of the type which method is to be invoked. Optional method parameters. Returns MethodInfo return value Delegate which is used as a return type for AsmHelper.GetMethodInvoker(). AsmHelper.GetStaticMethod() and AsmHelper.GetMethod() allow obtaining dynamic method delegate emitted on the base of the MethodInfo (from the compiled script type). Optional method parameters. Returns MethodInfo return value Delegate which is used as a return type for AsmHelper.GetMethodInvoker(). AsmHelper.GetStaticMethod() and AsmHelper.GetMethod() allow obtaining dynamic method delegate emitted on the base of the MethodInfo (from the compiled script type). The delegate return type. Optional method parameters. Returns MethodInfo return value Helper class to simplify working with dynamically loaded assemblies. Aligns (pseudo typecasts) object to the specified interface. The object does not necessarily need to implement the interface formally. See . The important difference between this method being called from working with the assembly in current and remote is that is that the actual interface alignment is performed in the corresponding . Interface definition to align with. The object to be aligned with the interface. Interface object. Aligns (pseudo typecasts) object to the specified interface. The object does not necessarily need to implement the interface formally. See . The important difference between this method being called from working with the assembly in current and remote is that is that the actual interface alignment is performed in the corresponding . Interface definition to align with. The object to be aligned with the interface. The string array containing file names to the additional dependency assemblies the interface depends in. Interface object. Aligns (pseudo typecasts) object to the specified interface. The object does not necessarily need to implement the interface formally. See . The important difference between this method being called from working with the assembly in current and remote is that is that the actual interface alignment is performed in the corresponding . Interface definition to align with. The object to be aligned with the interface. If set to true uses all loaded assemblies of the current Interface object. Creates object in remote or current and aligns (pseudo typecasts) it to the specified interface. Semantically it is an equivalent of calling asmHelper.AlignToInterface(asmHelper.CreateObject(typeName)) Interface definition to align with. The 'Type' full name of the type to create. (see Assembly.CreateInstance()). You can use wild card meaning the first type found. However only full wild card "*" is supported. The non default constructor arguments. Interface object. Instance of the AppDomain, which is used to execute the script. Reference to the "worker" object created in the remote AppDomain. This property is null unless was instantiated for the remote execution scenario. This property can be useful when you need to access the remote object in order to manage the "life time" of the AsmHelper in Remoting and WCF scenarios. var scriptHelper = new AsmHelper(scriptAsmFile, null, true); scriptHelper.RemoteObject.ExtendLifeFromMinutes(30); Flag that indicates if method caching is enabled. It is set to true by default. When caching is enabled AsmHelper generates (emits) extremely fast delegates for the methods being invoked. If AsmHelper is in cache mode it performs more than twice faster. However generation of the delegate does take some time that is why you may consider switching caching off if the method is to be invoked only once. Gets or sets a value indicating whether to unpack TargetInvocationExceptions. Script are often invoked via Reflection with , what leads to the script internal runrtime exceptions to be wrapped into noninformative . Thus by default unwraps the internal exception and rethrows it withour an additional container. While this is a more convenient approach, sometimes it may be required to investigate the Reflection callstack. Then you will need to suppress unpacking with this very property. true if unpack ; otherwise, false. This method returns extremely fast delegate for the method specified by "methodName" and method arguments "list". Invoking such delegate is ~100 times faster than invoking with pure reflection (MethodInfo.Invoke()). 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowd to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or "*.*"). List of 'Method' arguments. Note that values of the items in the list do not have any importance. The type of the list item is to be used for method search. For example if class Calc has method Sum(int a, int b) the method invoker can be obtained as following: GetMethodInvoker("Calc.Sum", 0, 0) You can pass any integer as the second and third parameter because it will be used only to obtain the information about the parameter type (in this case System.Int32). Returns delegate of CSScriptLibrary.FastInvokeDelegate type. Specialized version of GetMethodInvoker which returns MethodDelegate thus you do not need to specify object instance (null) when calling static methods. 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or "*.*"). List of 'Method' arguments. Returns delegate of CSScriptLibrary.MethodDelegate type. Note that values of the items in the list do not have any importance. The type of the list item is to be used for method search. For example if class Calc has method Sum(int a, int b) the method invoker can be obtained as following: GetStaticMethod("Calc.Sum", 0, 0) You can pass any integer as the second and third parameter because it will be used only to obtain the information about the parameter type (in this case System.Int32). Specialized version of GetMethodInvoker which returns MethodDelegate thus you do not need to specify object instance (null) when calling static methods. The delegate return type. 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or "*.*"). List of 'Method' arguments. Returns delegate of CSScriptLibrary.MethodDelegate type. Note that values of the items in the list do not have any importance. The type of the list item is to be used for method search. For example if class Calc has method Sum(int a, int b) the method invoker can be obtained as following: GetStaticMethod("Calc.Sum", 0, 0) You can pass any integer as the second and third parameter because it will be used only to obtain the information about the parameter type (in this case System.Int32). Specialized version of GetMethodInvoker which returns MethodDelegate thus you do not need to specify object instance (null) when calling static methods. 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or "*.*"). List of 'Method' arguments. Returns delegate of CSScriptLibrary.MethodDelegate type. Specialized version of GetMethodInvoker which returns MethodDelegate thus you do not need to specify object instance (null) when calling static methods. The delegate return type. 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or "*.*"). List of 'Method' arguments. Returns delegate of CSScriptLibrary.MethodDelegate type. Specialized version of GetMethodInvoker which returns MethodDelegate of the very first method found in the underlying assembly. This method is an overloaded implementation of the GetStaticMethod(string methodName, params object[] list). Use this method when script assembly contains only one single type with one method. Returns delegate of CSScriptLibrary.MethodDelegate type. Specialized version of GetMethodInvoker which returns MethodDelegate of the very first method found in the underlying assembly. This method is an overloaded implementation of the GetStaticMethod(string methodName, params object[] list). Use this method when script assembly contains only one single type with one method. The delegate return type. Returns delegate of CSScriptLibrary.MethodDelegate type. Specialized version of GetMethodInvoker which returns MethodDelegate thus you do not need to specify object instance when calling instance methods as delegate will maintain the instance object internally. Instance of the type, which implements method is to be wrapped by MethodDelegate. 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or "*.*"). List of 'Method' arguments. Note that values of the items in the list do not have any importance. The type of the list item is to be used for method search. For example if class Calc has method Sum(int a, int b) the method invoker can be obtained as following: GetMethod(instance, "Sum", 0, 0) You can pass any integer as the second and third parameter because it will be used only to obtain the information about the parameter type (in this case System.Int32). Returns delegate of CSScriptLibrary.MethodDelegate type. Specialized version of GetMethodInvoker which returns MethodDelegate thus you do not need to specify object instance when calling instance methods as delegate will maintain the instance object internally. The delegate return type. Instance of the type, which implements method is to be wrapped by MethodDelegate. 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or "*.*"). List of 'Method' arguments. Note that values of the items in the list do not have any importance. The type of the list item is to be used for method search. For example if class Calc has method Sum(int a, int b) the method invoker can be obtained as following: GetMethod(instance, "Sum", 0, 0) You can pass any integer as the second and third parameter because it will be used only to obtain the information about the parameter type (in this case System.Int32). Returns delegate of CSScriptLibrary.MethodDelegate type. Creates an instance of AsmHelper for working with assembly dynamically loaded to current AppDomain. Calling "Dispose" is optional for "current AppDomain"scenario as no new AppDomain will be ever created. Assembly object. Creates an instance of AsmHelper for working with assembly dynamically loaded to non-current AppDomain. This method initializes instance and creates new ('remote') AppDomain with 'domainName' name. New AppDomain is automatically unloaded as result of "disposable" behaviour of AsmHelper. The fully qualified path of the assembly file to load. Name of the domain to be created. 'true' if assembly file should be deleted when new AppDomain is unloaded; otherwise, 'false'. Executes static method of the underlying assembly. 'Method' name including 'Type' name (e.g. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method"). List of 'Method' arguments. Returns object of the same type as 'Method' return type. Executes an instance method of the underlying assembly. Instance of the object whose method is to be invoked. 'Method' name (excluding 'Type' name). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or even "*.*"). List of 'Method' arguments. Returns object of the same type as 'Method' return type. Gets the information about the object members.

This is an extremely light way of getting Reflection information of a given object. Object can be either local one or a TransparentProxy of the object instantiated in a remote AppDomain.

Note: Because none of the MemberInfo derivatives is serializable. This makes it impossible to use Reflection for discovering the type members instantiated in the different AppDomains. And the TransparentProxies do not provide any marshaled Reflection API neither. using (var helper = new AsmHelper(CSScript.CompileCode(code), null, true)) { var script = helper.CreateObject("Script"); //script code has 'class Script' declared foreach (string info in helper.GetMembersOf(script)) Debug.WriteLine(info); }
The object. Collection of strings with each item representing human readable information about the Type member. Type implementation: class Script { public void SayHello(string greeting) { ... Type member information: "MemberType:Method;Name:SayHello;DeclaringType:Script;Signature:Void SayHello(System.String)"
Attempts to create instance of a class from underlying assembly. The 'Type' full name of the type to create. (see Assembly.CreateInstance()). You can use wild card meaning the first type found. However only full wild card "*" is supported. The non default constructor arguments. Instance of the 'Type'. Returns null if the instance cannot be created. Creates instance of a class from underlying assembly. The 'Type' full name of the type to create. (see Assembly.CreateInstance()). You can use wild card meaning the first type found. However only full wild card "*" is supported. The non default constructor arguments. Instance of the 'Type'. Throws an ApplicationException if the instance cannot be created. Unloads 'remote' AppDomain if it was created. Implementation of IDisposable.Dispose(). Disposes allocated external resources if any. Call this method to unload non-current AppDomain (if it was created). Actual implementation of IDisposable.Dispose() 'false' if the method has been called by the runtime from inside the finalizer ; otherwise, 'true'. Finalizer Array of directories to be used for assembly probing. Defines method for calling assembly methods and instantiating assembly types. Creates instance of a Type from underlying assembly. Name of the type to be instantiated. Allows wild card character (e.g. *.MyClass can be used to instantiate MyNamespace.MyClass). The non default constructor arguments. Created instance of the type. Class which is capable of emitting the dynamic method delegate based on the MethodInfo. Such delegate is extremely fast and it can demonstrate up to 100 times better performance comparing to the pure Reflection method invokation (MethodInfo.Invoke()). Based on http://www.codeproject.com/KB/cs/FastInvokerWrapper.aspx MethodInfo instance which was used to generate dynamic method delegate. Constructor MethodInfo instance which is to be used to generate dynamic method delegate. Invokes dynamic method delegate generated from the MethodInfo object. Instance of the type which method is to be invoked. Optional method parameters. Invokes dynamic method delegate return value Returns dynamic method delegate generated from the MethodInfo object. FastInvokeDelegate instance. Class which is implements CS-Script class library interface. Global instance of . This object is to be used for dynamic loading of the C# code by using CodeDom "compiler as service". If you need to use multiple instances of th evaluator then you will need to call .Clone(). The instance. Global instance of . This object is to be used for dynamic loading of the C# code by using Roslyn "compiler as service". If you need to use multiple instances of th evaluator then you will need to call .Clone(). The instance. Gets the CSScript., which controls the way code evaluation is conducted at runtime. The evaluator CSScript.. Global instance of the generic . This object is to be used for dynamic loading of the C# code by "compiler as service" based on the value. Generic interface provides a convenient way of accessing compilers without 'committing' to a specific compiler technology (e.g. Mono, Roslyn, CodeDOM). This may be required during troubleshooting or performance tuning. Switching between compilers can be done via global CSScript.. By default CSScript. always returns a new instance of . If this behavior is undesired change the evaluator access policy by setting .Access value. The instance. if(testingWithMono) CSScript.EvaluatorConfig.Engine = EvaluatorEngine.Mono; else CSScript.EvaluatorConfig.Engine = EvaluatorEngine.Roslyn; var sub = CSScript.Evaluator .LoadDelegate<Func<int, int, int>>( @"int Sub(int a, int b) { return a - b; }"); Global instance of . This object is to be used for dynamic loading of the C# code by using Mono "compiler as service". If you need to use multiple instances of th evaluator then you will need to call .Clone(). For the majority of the CS-Script script engine hosting scenarios the Mono compiler is a preferred runtime. The major advantage is the compilation speed and superior (comparing to CodeDOM) memory management. The instance. Default constructor Determines whether the specified assembly is a script assembly (compiled script) and returns full path of the script file used to compile the assembly. The analysis is based on the fact that script assembly (in hosing scenarios) is always stamped with , which contains name of the script file the assembly was compiled from. The format of the description The assembly. Script file path if the specified assembly is a script assembly otherwise null. Force caught exceptions to be re-thrown. Aggregates the referenced assemblies found by parser. The parser. Extra search/probing directories. The default reference assemblies. It is a semicolon separated assembly names string (e.g. "System.Core; System.Linq;"). Enables automatic resolving of unsuccessful assembly probing on the base of the Settings.SearchDirs. Default value is true. CLR does assembly probing only in GAC and in the local (with respect to the application) directories. CS-Script however allows you to specify extra directory(es) for assembly probing by setting enabling CS-Script assembly resolving through setting the AssemblyResolvingEnabled to true and changing the Settings.SearchDirs appropriately. Gets or sets a value indicating whether setting 'location:<assm_hash>' environment variable is enabled. This variable is useful for finding the compiled assembly file from the inside of the script code. Even when the script loaded in-memory (InMemoryAssembly setting) but not from the original file. // called from the script code var asm_hash = Assembly.GetExecutingAssembly().GetHashCode(); var script_location = Environment.GetEnvironmentVariable(\"location:\" + asm_hash); Enabling script reflection can lead to exhausting the capacity of the process environment variables dictionary. That is why this feature is disabled by default. true if script location reflection is enabled otherwise, false. Gets or sets the assembly sharing mode. If set to true all assemblies (including the host assembly itself) currently loaded to the host application AppDomain are automatically available/accessible from the script code. Default value is true. Sharing the same assembly set between the host application and the script require AssemblyResolvingEnabled to be enabled. Whenever SharesHostRefAssemblies is changed to true it automatically sets AssemblyResolvingEnabled to true as well. Settings object containing runtime settings, which controls script compilation/execution. This is Settings class essentially is a deserialized content of the CS-Script configuration file (css_config.xml). Collection of all compiling results. Every time the script is compiled the compiling result is added to this collection regardless of the success or failure of the actual compilation. The hosting concurrency control. ProcessScope Mutex name is a derived from the hosting process id. Two calls to compile any script will be synchronized if the calls are made from the same host process. ScriptProcessScope Mutex name is a derived from the combination of the script path and hosting process id. Two calls to compile the same script file will be synchronized but only if the calls are made from the same host process. ScriptSystemScope Mutex name is a derived from the script path. Two calls to compile the same script file will be synchronized system wide. The last script compilation result. Note, invoking CSScript.Compile/CSScript.Load may not trigger the actual compilation if script caching is engaged. Thus the LastCompilingResult value can be null. Gets or sets a value indicating whether compiling history should be kept. The compilation results are stored in . true if compiling history should be kept; otherwise, false. Invokes global (static) CSExecutor (C# script engine) Print delegate to be used (if not null) to handle script engine output (eg. compilation errors). Script arguments. Invokes CSExecutor (C# script engine) Print delegate to be used (if not null) to handle script engine output (eg. compilation errors). Script arguments. Flag, which indicated if script exceptions should be rethrowed by the script engine without any handling. Compiles script code into assembly with CSExecutor The script code to be compiled. The string array containing file nemes to the additional assemblies referenced by the script. Compiled assembly file name. Compiles script code into assembly with CSExecutor The script code to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Returns the name of the temporary file in the CSSCRIPT subfolder of Path.GetTempPath(). Temporary file name. Returns the name of the CSScript temporary folder. Temporary folder name. Compiles multiple C# files into a single assembly with CSExecutor Collection of the files to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Compiles multiple C# files into a single assembly with CSExecutor Collection of the files to be compiled. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Compiles script file into assembly with CSExecutor The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Compiles script file into assembly with CSExecutor The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Compiles script file into assembly (temporary file) with CSExecutor. This method is an equivalent of the CSScript.Compile(scriptFile, null, false); The path to the script file to be compiled. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Compiles script file into assembly (temporary file) with CSExecutor. This method is an equivalent of the CSScript.Compile(scriptFile, null, false); The path to script file to be compiled. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Compiles script file into assembly with CSExecutor. Uses specified config file to load script engine settings. The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The name of CS-Script configuration file. If null the default config file will be used (appDir/css_config.xml). Compiled assembly file name. Compiles script file into assembly with CSExecutor. Uses specified config file to load script engine settings and compiler specific options. The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The name of CS-Script configuration file. If null the default config file will be used (appDir/css_config.xml). The string value to be passed directly to the language compiler. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Creates the compiler lock object (). The Mutex object is now initially owned. This object is to be used for the access synchronization to the compiled script file and it can be useful for the tasks like cache purging or explicit script recompilation. The optimisticConcurrencyModel has the same meaning as . And it is to be used to control the concurrency scope. The script file. if set to true the operation is thread-safe within the current process. Otherwise the operation is thread-safe system wide. Creates the compiler lock object (). The Mutex object is now initially owned. This object is to be used for the access synchronization to the compiled script file and it can be useful for the tasks like cache purging or explicit script recompilation. The concurrency/lock scope is controlled by . And it is to be used to control the concurrency scope. The script file. Compiles script file into assembly with CSExecutor. Uses script engine settings object and compiler specific options. The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The script engine Settings object. The string value to be passed directly to the language compiler. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Compiles script file into assembly with CSExecutor. Uses script engine settings object and compiler specific options. The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The script engine Settings object. The string value to be passed directly to the language compiler. The compiling information. Populated with the compilation context. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly file name. Surrounds the method implementation code into a class and compiles it code into assembly with CSExecutor and loads it in current AppDomain. The most convenient way of using dynamic methods is to declare them as static methods. In this case they can be invoked with wild card character as a class name (e.g. asmHelper.Invoke("*.SayHello")). Otherwise you will need to instantiate class "DyamicClass.Script" in order to call dynamic method. You can have multiple methods implementations in the single methodCode. Also you can specify namespaces at the beginning of the code: CSScript.LoadMethod( @"using System.Windows.Forms; public static void SayHello(string greeting) { MessageBoxSayHello(greeting); ConsoleSayHello(greeting); } public static void MessageBoxSayHello(string greeting) { MessageBox.Show(greeting); } public static void ConsoleSayHello(string greeting) { Console.WriteLine(greeting); }"); The C# code, containing method implementation. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of T delegate for the first method in the auto-generated class. The following is the simple example of the interface alignment: var Product = CSScript.LoadDelegate<Func<int, int, int>>( @"int Product(int a, int b) { return a * b; }"); int result = Product(3, 2); The C# code. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Instance of T delegate. Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of for the first method in the auto-generated class. The following is the simple example of the interface alignment: var SayHello = CSScript.CreateAction(@"void SayHello(string greeting) { Console.WriteLine(greeting); }"); SayHello("Hello World!"); The C# code. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Instance of . Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of for the first method in the auto-generated class. The following is the simple example of the interface alignment: var product = CSScript.CreateFunc<intgt;(@"int Product(int a, int b) { return a * b; }"); int result = product(3, 4); The delegate return type. The C# code. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Instance of . Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of T delegate for the first method in the auto-generated class. The following is the simple example of the interface alignment: var Product = CSScript.LoadDelegate<Func<int, int, int>>( @"int Product(int a, int b) { return a * b; }"); int result = Product(3, 2); The C# code. Instance of T delegate. Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of for the first method in the auto-generated class. The following is the simple example of the interface alignment: var SayHello = CSScript.CreateAction(@"void SayHello(string greeting) { Console.WriteLine(greeting); }"); SayHello("Hello World!"); The C# code. Instance of . Stop any running instances of the compiler server if any. Stopping is needed in order to prevent any problems with copying/moving CS-Script binary files (e.g. Roslyn compilers). Servers restart automatically on any attempt to compile any C#/VB.NET code by any client (e.g. Visual Studio, MSBuild, CS-Script). Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of for the first method in the auto-generated class. The following is the simple example of the interface alignment: var product = CSScript.CreateFunc<intgt;(@"int Product(int a, int b) { return a * b; }"); int result = product(3, 4); The delegate return type. The C# code. Instance of . Surrounds the method implementation code into a class and compiles it code into assembly with CSExecutor and loads it in current AppDomain. The most convenient way of using dynamic methods is to declare them as static methods. In this case they can be invoked with wild card character as a class name (e.g. asmHelper.Invoke("*.SayHello")). Otherwise you will need to instantiate class "DyamicClass.Script" in order to call dynamic method. You can have multiple methods implementations in the single methodCode. Also you can specify namespaces at the beginning of the code: CSScript.LoadMethod( @"using System.Windows.Forms; public static void SayHello(string greeting) { MessageBoxSayHello(greeting); ConsoleSayHello(greeting); } public static void MessageBoxSayHello(string greeting) { MessageBox.Show(greeting); } public static void ConsoleSayHello(string greeting) { Console.WriteLine(greeting); }"); The C# code, containing method implementation. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles script code from the specified file into assembly with CSExecutor and loads it in current AppDomain. This method is a logical equivalent of the corresponding LoadCode method except the code is not specified as a call argument but read from the file instead. It is recommended to use LoadFrom method instead as it is more straight forward and arguably faster. Use LoadCodeFrom only if you indeed want to disassociate your script code from the script file or if the original location of the source file some how is incompatible with the actual C# compiler. The script file. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles code from the specified files into assembly with CSExecutor and loads it in current AppDomain. This method is a logical equivalent of the corresponding LoadCode method except the code is not specified as a call argument but read from the file instead. The source files to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles code from the specified files into assembly with CSExecutor and loads it in current AppDomain. This method is a logical equivalent of the corresponding LoadCode method except the code is not specified as a call argument but read from the file instead. The source files to be compiled. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles script code from the specified file into assembly with CSExecutor and loads it in current AppDomain. This method is a logical equivalent of the corresponding LoadCode method except the code is not specified as a call argument but read from the file instead. It is recommended to use LoadFrom method instead as it is more straight forward and arguably faster. Use LoadCodeFrom only if you indeed want to disassociate your script code from the script file or if the original location of the source file some how is incompatible with the actual C# compiler. The script file. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles script code from the specified file into assembly with CSExecutor and loads it in current AppDomain. This method is a logical equivalent of the corresponding LoadCode method except the code is not specified as a call argument but read from the file instead. It is recommended to use LoadFrom method instead as it is more straight forward and arguably faster. Use LoadCodeFrom only if you indeed want to disassociate your script code from the script file or if the original location of the source file some how is incompatible with the actual C# compiler. The script file. The file extension of the temporary file to hold script code during compilation. This parameter may be needed if custom CS-Script compilers rely on file extension to identify the script syntax. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles script code into assembly with CSExecutor and loads it in current AppDomain. The script code to be compiled. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles script code into assembly with CSExecutor and loads it in current AppDomain. The script code to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Compiles script code into assembly with CSExecutor and loads it in current AppDomain. The script code to be compiled. The file extension of the temporary file to hold script code during compilation. This parameter may be needed if custom CS-Script compilers rely on file extension to identify the script syntax. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled assembly. Cleans up all abandoned dynamic C# sources (temp files) generated by LodCode*() API methods. You don't need to use this method as it is scheduled for execution at the end of the application. However automatic cleanup may fail under certain circumstances as it is scheduled by the AppDomain.CurrentDomain.ProcessExit event, which is not guaranteed to be always executed. In such cases or if you want to clear the directory prior the execution you can call CSScript.CleanupDynamicSources() explicitly. Compiles script file into assembly with CSExecutor and loads it in current AppDomain The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled/Loaded assembly. Compiles script file into assembly with CSExecutor and loads it in current AppDomain The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The string array containing file names to the additional assemblies referenced by the script. Compiled/Loaded assembly. Compiles script file into assembly with CSExecutor and loads it in current AppDomain The path to the script file to be compiled. The path of the compiled assembly to be created. If set to null a temporary file name will be used. 'true' if debug information should be included in assembly; otherwise, 'false'. The script engine Settings object. You can pass null to load CSScript.GlobalSettings. The string value to be passed directly to the language compiler. The string array containing file names to the additional assemblies referenced by the script. Compiled/Loaded assembly. Compiles script file into assembly (temporary file) with CSExecutor and loads it in current AppDomain. This method is an equivalent of the CSScript.Load(scriptFile, null, false); The path to the script file to be compiled. Compiled/Loaded assembly. Compiles script file into assembly (temporary file) with CSExecutor and loads it in current AppDomain. This method is an equivalent of the CSScript.Load(scriptFile, null, false); The path to the script file to be compiled. Compiled/Loaded assembly. Compiles script file into assembly (temporary file) with CSExecutor and loads it in current AppDomain. This method is an equivalent of the CSScript.Load(scriptFile, null, false); The path to the script file to be compiled. The string array containing file names to the additional assemblies referenced by the script. Compiled/Loaded assembly. Compiles script file into assembly (temporary file) with CSExecutor and loads it in current AppDomain. This method is an equivalent of the CSScript.Load(scriptFile, null, false); The path to the script file to be compiled. The string array containing file names to the additional assemblies referenced by the script. Compiled/Loaded assembly. Default implementation of displaying application messages. LoadedScript is a class, which holds information about the script file location and it's compiled and loaded assmbly (current AppDomain). Creates instance of LoadedScript Script file location. Compiled script assembly loaded into current AppDomain. Script file location. Compiled script assembly loaded into current AppDomain. Controls if ScriptCache should be used when script file loading is requested (CSScript.Load(...)). If set to true and the script file was previously compiled and already loaded the script engine will use that compiled script from the cache instead of compiling it again. Note the script cache is always maintained by the script engine. The CacheEnabled property only indicates if the cached script should be used or not when CSScript.Load(...) method is called. Ignores the system wide configuration for CS-Script (e.g. default referenced assemblies, alternative compiler). Folder where the current system wide configuration file (css_config.xml) is located. The resolve source file algorithm. The default algorithm searches for script file by given script name. Search order: 1. Current directory 2. extraDirs (usually %CSSCRIPT_DIR%\Lib and ExtraLibDirectory) 3. PATH Also fixes file name if user did not provide extension for script file (assuming .cs extension) If the default implementation isn't suitable then you can set CSScript.ResolveSourceAlgorithm to the alternative implementation of the probing algorithm. Resolves namespace/assembly(file) name into array of assembly locations (local and GAC ones). If the default implementation isn't suitable then you can set CSScript.ResolveAssemblyAlgorithm to the alternative implementation of the probing algorithm. collection of assembly file names where namespace is implemented Cache of all loaded script files for the current process. Returns file path of the cached script assembly matching the script file name. Script file path. Path to the previously compiled script assembly. Returns null if the cached script cannot be found. Returns loaded cached script assembly matching the script file name. Script file path. Assembly loaded in the current AppDomain. Returns null if the loaded script cannot be found. Returns path to the cached script assembly matching the script file name. Script file path. Cached (compiled) script assembly file path. Compiled script probing handler. Analyses the script file and the compiled script (script assembly) and determines if the script assembly is out of data and needs to be recompiled. The default implementation is . You can always supply your custom algorithm. For example

CSScript.IsOutOfDateAlgorithm = (s, a) => true;

fill force CS-Script to recompile the script every time it is loaded.
Compiled script probing handler. Analyses the script file and the compiled script (script assembly) and determines if the script assembly is out of data and needs to be recompiled. The default implementation is . You can always supply your custom algorithm. For example

CSScript.IsOutOfDate = (s, a) => true;

will force CS-Script to recompile the script every time it is loaded.
This class contains default implementations of the . Gets the simplified IsOutOfDateAlgorithm implementation. The implementation is based on analysis of the 'LastWriteTimeUtc' timestamps of the script and compiled script assembly. But not the script dependencies. Gets the comprehensive IsOutOfDateAlgorithm implementation. The implementation is based on analysis of the 'LastWriteTimeUtc' timestamps of the script, compiled script assembly and all script dependencies. A wrapper class that encapsulates the functionality of the CodeDom evaluator (). Initializes a new instance of the class. Clones itself as . This method returns a freshly initialized copy of the . The cloning 'depth' can be controlled by the . This method is a convenient technique when multiple instances are required (e.g. for concurrent script evaluation). if set to true all referenced assemblies from the parent will be referenced in the cloned copy. The freshly initialized instance of the . Gets or sets a value indicating whether to compile script with debug symbols. Note, currently only CodeDom fully supports generation of debugging symbols. true if 'debug build'; otherwise, false. Evaluates (compiles) C# code (script). The C# code is a typical C# code containing a single or multiple class definition(s). Assembly asm = CSScript.CodeDomEvaluator .CompileCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); dynamic script = asm.CreateObject("*"); var result = script.Sum(7, 3); The C# script text. The compiled assembly. Gets or sets the flag indicating if the script code should be analyzed and the assemblies that the script depend on (via '//css_...' and 'using ...' directives) should be referenced. Wraps C# code fragment into auto-generated class (type name DynamicClass) and evaluates it. This method is a logical equivalent of but is allows you to define your script class by specifying class method instead of whole class declaration. dynamic script = CSScript.CodeDomEvaluator .CompileMethod(@"int Sum(int a, int b) { return a+b; }") .CreateObject("*"); var result = script.Sum(7, 3); The C# code. The compiled assembly. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns non-typed for class-less style of invoking. var log = CSScript.CodeDomEvaluator .CreateDelegate(@"void Log(string message) { Console.WriteLine(message); }"); log("Test message"); The C# code. The instance of a non-typed Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns typed for class-less style of invoking. The delegate return type. var product = CSScript.CodeDomEvaluator .CreateDelegate<int>(@"int Product(int a, int b) { return a * b; }"); int result = product(3, 2); The C# code. The instance of a typed Loads and returns set of referenced assemblies. Notre: the set of assemblies is cleared on Reset. Analyses the script code and returns set of locations for the assemblies referenced from the code with CS-Script directives (//css_ref). The script code. The assembly search/probing directories. Array of the referenced assemblies Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. The following is the simple example of the LoadCode usage: dynamic script = CSScript.CodeDomEvaluator .LoadCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = script.Sum(1, 2); The C# script text. The non default constructor arguments. Instance of the class defined in the script. Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: Because the interface alignment is a duck typing implementation the script class doesn't have to inherit from T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.CodeDomEvaluator .LoadCode<ICalc>(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. The non default type T constructor arguments. Aligned to the T interface instance of the class defined in the script. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of T delegate for the first method in the auto-generated class. var Product = CSScript.CodeDomEvaluator .LoadDelegate<Func<int, int, int>>( @"int Product(int a, int b) { return a * b; }"); int result = Product(3, 2); The C# code. Instance of T delegate. Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. The following is the simple example of the interface alignment: dynamic script = CSScript.CodeDomEvaluator .LoadFile("calc.cs"); int result = script.Sum(1, 2); /// The C# script file. Instance of the class defined in the script file. Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: the script class does not have to inherit from the T parameter as the proxy type will be generated anyway. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.CodeDomEvaluator .LoadFile<ICalc>("calc.cs"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the class defined in the script file. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. The following is the simple example of the LoadMethod usage: dynamic script = CSScript.CodeDomEvaluator .LoadMethod(@"int Product(int a, int b) { return a * b; }"); int result = script.Product(3, 2); The C# script text. Instance of the first class defined in the script. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. After initializing the class instance it is aligned to the interface specified by the parameter T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); int Div(int a, int b); } .... ICalc script = CSScript.CodeDomEvaluator .LoadMethod<ICalc>(@"public int Sum(int a, int b) { return a + b; } public int Div(int a, int b) { return a/b; }"); int result = script.Div(15, 3); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the auto-generated class defined in the script. References the assemblies from the script code. The method analyses and tries to resolve CS-Script directives (e.g. '//css_ref') and 'used' namespaces based on the optional search directories. The script code. The assembly search/probing directories. The instance of the to allow fluent interface. References the given assembly by the assembly path. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The path to the assembly file. The instance of the to allow fluent interface. References the given assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The assembly instance. The instance of the to allow fluent interface. References the name of the assembly by its partial name. Note that the referenced assembly will be loaded into the host AppDomain in order to resolve assembly partial name. It is an equivalent of Evaluator.ReferenceAssembly(Assembly.LoadWithPartialName(assemblyPartialName)) Partial name of the assembly. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. The namespace. Set to true if the namespace was successfully resolved (found) and the reference was added; otherwise, false. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. Adds assembly reference if the namespace was successfully resolved (found) and, otherwise does nothing The namespace. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The object, which belongs to the assembly to be referenced. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The type which is implemented in the assembly to be referenced. The instance of the to allow fluent interface. References the assemblies the are already loaded into the current AppDomain. The type of assemblies to be referenced. The instance of the to allow fluent interface. Resets Evaluator. Resetting means clearing all referenced assemblies, recreating evaluation infrastructure (e.g. compiler setting) and reconnection to or recreation of the underlying compiling services. Optionally the default current AppDomain assemblies can be referenced automatically with . if set to true the default assemblies of the current AppDomain will be referenced (see method). The freshly initialized instance of the . Method extensions for Roslyn. Single step evaluating method for Roslyn compiler. Compiles specified code, loads the compiled assembly and returns it to the caller. The code. A wrapper class that encapsulates the functionality of the Roslyn evaluator (). Gets or sets a value indicating whether to compile script with debug symbols. Note, affect of setting DebugBuild will always depend on the compiler implementation: CodeDomFully supports. Generates debugging symbols (script can be debugged) and defines DEBUG and TRACE conditional symbols MonoPartially supports. Defines DEBUG and TRACE conditional symbols RoslynDoesn't supports at all. true if 'debug build'; otherwise, false. Initializes a new instance of the class. Clones itself as . This method returns a freshly initialized copy of the . The cloning 'depth' can be controlled by the . This method is a convenient technique when multiple instances are required (e.g. for concurrent script evaluation). if set to true all referenced assemblies from the parent will be referenced in the cloned copy. The freshly initialized instance of the . Gets or sets the compiler settings. The compiler settings. Loads the assemblies implementing Roslyn compilers. Roslyn compilers are extremely heavy and loading the compiler assemblies for with the first evaluation call can take a significant time to complete (in some cases up to 4 seconds) while the consequent calls are very fast. You may want to call this method to pre-load the compiler assembly your script evaluation performance. Evaluates (compiles) C# code (script). The C# code is a typical C# code containing a single or multiple class definition(s). Assembly asm = CSScript.RoslynEvaluator .CompileCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); dynamic script = asm.CreateObject("*"); var result = script.Sum(7, 3); The C# script text. The compiled assembly. Wraps C# code fragment into auto-generated class (type name DynamicClass) and evaluates it. This method is a logical equivalent of but is allows you to define your script class by specifying class method instead of whole class declaration. dynamic script = CSScript.RoslynEvaluator .CompileMethod(@"int Sum(int a, int b) { return a+b; }") .CreateObject("*"); var result = script.Sum(7, 3); The C# code. The compiled assembly. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns non-typed for class-less style of invoking. var log = CSScript.RoslynEvaluator .CreateDelegate(@"void Log(string message) { Console.WriteLine(message); }"); log("Test message"); The C# code. The instance of a non-typed Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns typed for class-less style of invoking. The delegate return type. var product = CSScript.RoslynEvaluator .CreateDelegate<int>(@"int Product(int a, int b) { return a * b; }"); int result = product(3, 2); The C# code. The instance of a typed Returns set of referenced assemblies. Notre: the set of assemblies is cleared on Reset. Analyses the script code and returns set of locations for the assemblies referenced from the code with CS-Script directives (//css_ref). The script code. The assembly search/probing directories. Array of the referenced assemblies Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. The following is the simple example of the LoadCode usage: dynamic script = CSScript.RoslynEvaluator .LoadCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = script.Sum(1, 2); The C# script text. The non default constructor arguments. Instance of the class defined in the script. Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: Because the interface alignment is a duck typing implementation the script class doesn't have to inherit from T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.RoslynEvaluator .LoadCode<ICalc>(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. The non default type T constructor arguments. Aligned to the T interface instance of the class defined in the script. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of T delegate for the first method in the auto-generated class. var Product = CSScript.RoslynEvaluator .LoadDelegate<Func<int, int, int>>( @"int Product(int a, int b) { return a * b; }"); int result = Product(3, 2); The C# code. Instance of T delegate. Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. The following is the simple example of the interface alignment: dynamic script = CSScript.RoslynEvaluator .LoadFile("calc.cs"); int result = script.Sum(1, 2); /// The C# script file. Instance of the class defined in the script file. Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: the script class does not have to inherit from the T parameter as the proxy type will be generated anyway. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.Evaluator .LoadFile<ICalc>("calc.cs"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the class defined in the script file. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. The following is the simple example of the LoadMethod usage: dynamic script = CSScript.RoslynEvaluator .LoadMethod(@"int Product(int a, int b) { return a * b; }"); int result = script.Product(3, 2); The C# script text. Instance of the first class defined in the script. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. After initializing the class instance it is aligned to the interface specified by the parameter T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); int Div(int a, int b); } .... ICalc script = CSScript.RoslynEvaluator .LoadMethod<ICalc>(@"public int Sum(int a, int b) { return a + b; } public int Div(int a, int b) { return a/b; }"); int result = script.Div(15, 3); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the auto-generated class defined in the script. Gets or sets the flag indicating if the script code should be analyzed and the assemblies that the script depend on (via '//css_...' and 'using ...' directives) should be referenced. References the assemblies from the script code. The method analyses and tries to resolve CS-Script directives (e.g. '//css_ref') and 'used' namespaces based on the optional search directories. The script code. The assembly search/probing directories. The instance of the to allow fluent interface. References the given assembly by the assembly path. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The path to the assembly file. The instance of the to allow fluent interface. References the given assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The assembly instance. The instance of the to allow fluent interface. References the name of the assembly by its partial name. Note that the referenced assembly will be loaded into the host AppDomain in order to resolve assembly partial name. It is an equivalent of Evaluator.ReferenceAssembly(Assembly.LoadWithPartialName(assemblyPartialName)) Partial name of the assembly. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. The namespace. Set to true if the namespace was successfully resolved (found) and the reference was added; otherwise, false. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. Adds assembly reference if the namespace was successfully resolved (found) and, otherwise does nothing The namespace. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The object, which belongs to the assembly to be referenced. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The type which is implemented in the assembly to be referenced. The instance of the to allow fluent interface. References the assemblies the are already loaded into the current AppDomain. The type of assemblies to be referenced. The instance of the to allow fluent interface. Resets Evaluator. Resetting means clearing all referenced assemblies, recreating evaluation infrastructure (e.g. compiler setting) and reconnection to or recreation of the underlying compiling services. Optionally the default current AppDomain assemblies can be referenced automatically with . if set to true the default assemblies of the current AppDomain will be referenced (see method). The freshly initialized instance of the . Do not use as this interface as it's intended for use by CS-Script engine only. Interface that is used by CS-Script engine to build transparent proxies for EvaluatorRemoting extensions. This interface has to be public as it is passed across assemblies. The extremely simple implementation of generic "Extension Properties". Originally published on CodeProject: http://www.codeproject.com/Articles/399932/Extension-Properties-Revised Sets the named value to the object. The type of the value. The object. The name of the value. The value. Gets the named value of the object. The type of the value. The object. The name of the value. Gets the named value of the object. The object. The name of the value. Extension methods for invocation of methods in a remote AppDomain. Gets the remote AppDomain associated with the evaluator. The AppDomain is set to the Evaluator with the last call of any EvaluatorRemoting extension methods. The evaluator. Gets the owner/parent of the object. This method is used to access the remote object owning the MethodDelegate returned to the caller AppDomain with the EvaluatorRemoting extension methods. The type of the . The object. Gets the AppDomain owning the actual object the transparent proxy is associated with. The AppDomain is set to the proxy object on any EvaluatorRemoting extension methods call. The transparent proxy object. Unloads the AppDomain owning the actual object that the transparent proxy is associated with. The transparent proxy object. Loads the method remotely. LoadMethodRemotely is essentially the same as . It just deals not with the whole class definition but a method(s) only. And the rest of the class definition is added automatically by CS-Script. var script = CSScript.Evaluator .LoadMethodRemotely<ICalc>( @"public int Sum(int a, int b) { return a+b; } public int Sub(int a, int b) { return a-b; }"); int result = script.Sum(15, 3)); // after the next line call the remote domain with loaded script will be unloaded script.UnloadOwnerDomain(); The type of the T. The evaluator. The code. Loads the script file remotely. This method is essentially identical to . Except it loads the code not from the in-memory string but from the file. The interface type the remote object should be casted or aligned (duck-typed) to. The evaluator. The script file. Loads/evaluates C# code into a remote AppDomain and returns a transparent proxy of the instance of the first class defined in the code. The returned proxy can be used to unload the AppDomain owning the actual object the proxy points to. Note, the concrete type of the return value depends on the script class definition. It the class implement interface then an ordinary type castes proxy object is returned. However if the class doesn't implement the interface the a dynamically emitted duck-typed proxy returned instead. Such proxy cannot be built for the types implemented in file-less (in-memory) assemblies. Thus neither Mono nor Roslyn engines cannot be used with this technique. Meaning that needs to be used. While the script class to be evaluated doesn't have to implement from 'T' interface but it must inherit though. // duck-typed proxy; must use CodeDomEvaluator var script = CSScript.CodeDomEvaluator .LoadCodeRemotely<ICalc>( @"using System; public class Calc : MarshalByRefObject { public int Sum(int a, int b) { return a + b; } }"); // ordinary type casted proxy var script2 = CSScript.Evaluator .LoadCodeRemotely<ICalc>( @"using System; public class Calc : MarshalByRefObject : ICalc { public int Sum(int a, int b) { return a + b; } }"); int result = script.Sum(15, 3); // after the next line call the remote domain with loaded script will be unloaded script.UnloadOwnerDomain(); The interface type the remote object should be casted or aligned (duck-typed) to. The evaluator. The script code that defines the script class to be loaded. The script class doesn't have to implement from 'T' interface but it must inherit though. The probing directories for the assemblies the script assembly depends on. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the remote AppDomain. Returns non-typed of the remote object for class-less style of invoking. var log = CSScript.Evaluator .CreateDelegateRemotely( @"void Log(string message) { Console.WriteLine(message); }"); log("Test message"); log.UnloadOwnerDomain(); The evaluator. The C# code. The probing directories for the assemblies the script assembly depends on. The instance of a 'duck typed' Wraps C# code fragment into auto-generated class (type name DynamicClass) implementing interface T, evaluates it and loads the class to the remote AppDomain. Returns typed for class-less style of invoking. The delegate return type. var product = CSScript.Evaluator .CreateDelegateRemotely<int>( @"int Product(int a, int b) { return a * b; }"); int result = product(3, 2); product.UnloadOwnerDomain(); The evaluator. The C# code. The probing directories for the assemblies the script assembly depends on. The instance of a 'duck typed' Extension methods for asynchronous invocation of methods with Async and Await available in C# 5. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { Assembly script = await CSScript.Evaluator .CompileCodeAsync( @"using System; public class Calc { public int Sum(int a, int b) { return a+b; } }"); dynamic calc = script.CreateObject("*"); textBox1.Text = calc.Sum(3, 2).ToString(); } The evaluator. The C# code. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { Assembly script = await CSScript.Evaluator .CompileMethodAsync( @"int Sum(int a, int b) { return a+b; }"); dynamic calc = script.CreateObject("*"); textBox1.Text = calc.Sum(3, 7).ToString(); } The evaluator. The code. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { var product = await CSScript.Evaluator .CreateDelegateAsync<int>( @"int Product(int a, int b) { return a * b; }"); textBox1.Text = product(3, 2).ToString(); } The evaluator. The C# script text. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { var log = await CSScript.Evaluator .CreateDelegateAsync( @"void Log(string message) { Console.WriteLine(message); }"); log("Test message"); } The evaluator. The C# script text. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { dynamic calc = await CSScript.Evaluator .LoadCodeAsync( @"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); textBox1.Text = calc.Sum(1, 2).ToString(); } The evaluator. The C# script text. The non default type T constructor arguments. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { ICalc calc = await CSScript.Evaluator .LoadCodeAsync<ICalc>( @"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); textBox1.Text = calc.Sum(1, 2).ToString(); } The type of the interface type the script class instance should be aligned to. The evaluator. The C# script text. The non default type T constructor arguments. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { ICalc script = await CSScript.Evaluator .LoadFileAsync<ICalc>("calc.cs"); textBox1.Text = script.Sum(1, 2).ToString(); } The type of the T. The evaluator. The C# script file. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { dynamic script = await CSScript.Evaluator .LoadFileAsync("calc.cs"); textBox1.Text = script.Sum(1, 2).ToString(); } The evaluator. The C# script file. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { ICalc script = await CSScript.Evaluator .LoadMethodAsync<ICalc>( @"public int Sum(int a, int b) { return a + b; } public int Div(int a, int b) { return a/b; }"); textBox1.Text = script.Div(15, 3).ToString(); } The evaluator. The code. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { ICalc script = await CSScript.Evaluator .LoadMethodAsync<ICalc>( @"public int Sum(int a, int b) { return a + b; } public int Div(int a, int b) { return a/b; }"); textBox1.Text = script.Div(15, 3).ToString(); } The type of the T. The evaluator. The code. Asynchronous version of . async void button1_Click(object sender, EventArgs e) { var product = await CSScript.Evaluator .LoadDelegateAsync<Func<int, int, int>>( @"int Product(int a, int b) { return a * b; }"); textBox1.Text = product(3, 2).ToString(); } The type of the T. The evaluator. The code. Type of the assemblies to be loaded/referenced. No assemblies All static current AppDomain assemblies All static and non-GAC current AppDomain assemblies All current AppDomain assemblies Type of the evaluator engine. This enum is used to control type of compiler the generic CSScript. encapsulates. Roslyn compilation services Mono compilation services CodeDom compilation infrastructure Runtime instantiation model for CS-Script evaluators (e.g CSScript.). Every time the member variable is accessed the same static object is returned. Every time the member variable is accessed a new object is created. Class that contains configuration options for controlling dynamic code evaluation with CSScript.. Gets or sets the default access type for CS-Script evaluators. This property controls the how the generic CS-Script evaluators are instantiated when accessed (e.g. CSScript. or ). The access. Default value of the .DebugBuild property controlling the generation of the debug symbols. Flag that controls if the host AppDo,main referenced assemblies are automatically referenced at creation of . Gets or sets the default evaluator engine type. This property controls the type of compiler the generic CSScript. encapsulates. The default evaluator engine. A generic interface of the CS-Script evaluator. It encapsulates the generic functionality of the evaluator regardless of the nature of the underlying compiling services (e.g. Mono, Roslyn, CodeDom). Gets or sets a value indicating whether to compile script with debug symbols. Note, affect of setting DebugBuild will always depend on the compiler implementation: CodeDomFully supports. Generates debugging symbols (script can be debugged) and defines DEBUG and TRACE conditional symbols MonoPartially supports. Defines DEBUG and TRACE conditional symbols RoslynDoesn't supports at all. true if 'debug build'; otherwise, false. Gets or sets the flag indicating if the script code should be analyzed and the assemblies that the script depend on (via '//css_...' and 'using ...' directives) should be referenced. Evaluates (compiles) C# code (script). The C# code is a typical C# code containing a single or multiple class definition(s). Assembly asm = CSScript.Evaluator .CompileCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); dynamic script = asm.CreateObject("*"); var result = script.Sum(7, 3); The C# script text. The compiled assembly. Wraps C# code fragment into auto-generated class (type name DynamicClass) and evaluates it. This method is a logical equivalent of but is allows you to define your script class by specifying class method instead of whole class declaration. dynamic script = CSScript.Evaluator .CompileCode(@"int Sum(int a, int b) { return a+b; }") .CreateObject("*"); var result = script.Sum(7, 3); The C# code. The compiled assembly. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns non-typed for class-less style of invoking. var log = CSScript.Evaluator .CreateDelegate(@"void Log(string message) { Console.WriteLine(message); }"); log("Test message"); The C# code. The instance of a 'duck typed' Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns typed for class-less style of invoking. The delegate return type. var product = CSScript.Evaluator .CreateDelegate<int>(@"int Product(int a, int b) { return a * b; }"); int result = product(3, 2); The C# code. The instance of a typed Analyses the script code and returns set of locations for the assemblies referenced from the code with CS-Script directives (//css_ref). The script code. The assembly search/probing directories. Array of the referenced assemblies Returns set of referenced assemblies. Notre: the set of assemblies is cleared on Reset. Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. The following is the simple example of the LoadCode usage: dynamic script = CSScript.Evaluator .LoadCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = script.Sum(1, 2); The C# script text. The non default constructor arguments. Instance of the class defined in the script. Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: Because the interface alignment is a duck typing implementation the script class doesn't have to inherit from T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.Evaluator .LoadCode<ICalc>(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. The non default type T constructor arguments. Aligned to the T interface instance of the class defined in the script. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of T delegate for the first method in the auto-generated class. var Product = CSScript.Evaluator .LoadDelegate<Func<int, int, int>>( @"int Product(int a, int b) { return a * b; }"); int result = Product(3, 2); The C# code. Instance of T delegate. Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. The following is the simple example of the interface alignment: dynamic script = CSScript.Evaluator .LoadFile("calc.cs"); int result = script.Sum(1, 2); /// The C# script file. Instance of the class defined in the script file. Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: the script class does not have to inherit from the T parameter as the proxy type will be generated anyway. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.Evaluator .LoadFile<ICalc>("calc.cs"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the class defined in the script file. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. The following is the simple example of the LoadMethod usage: dynamic script = CSScript.Evaluator .LoadMethod(@"int Product(int a, int b) { return a * b; }"); int result = script.Product(3, 2); The C# script text. Instance of the first class defined in the script. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. After initializing the class instance it is aligned to the interface specified by the parameter T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); int Div(int a, int b); } .... ICalc script = CSScript.Evaluator .LoadMethod<ICalc>(@"public int Sum(int a, int b) { return a + b; } public int Div(int a, int b) { return a/b; }"); int result = script.Div(15, 3); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the auto-generated class defined in the script. References the assemblies from the script code. The method analyses and tries to resolve CS-Script directives (e.g. '//css_ref') and 'used' namespaces based on the optional search directories. The script code. The assembly search/probing directories. The instance of the to allow fluent interface. References the given assembly by the assembly path. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The path to the assembly file. The instance of the to allow fluent interface. References the given assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The assembly instance. The instance of the to allow fluent interface. References the name of the assembly by its partial name. Note that the referenced assembly will be loaded into the host AppDomain in order to resolve assembly partial name. It is an equivalent of Evaluator.ReferenceAssembly(Assembly.LoadWithPartialName(assemblyPartialName)) Partial name of the assembly. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. The namespace. Set to true if the namespace was successfully resolved (found) and the reference was added; otherwise, false. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. Adds assembly reference if the namespace was successfully resolved (found) and, otherwise does nothing The namespace. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The object, which belongs to the assembly to be referenced. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The type which is implemented in the assembly to be referenced. The instance of the to allow fluent interface. References the assemblies the are already loaded into the current AppDomain. The type of assemblies to be referenced. The instance of the to allow fluent interface. Resets Evaluator. Resetting means clearing all referenced assemblies, recreating evaluation infrastructure (e.g. compiler setting) and reconnection to or recreation of the underlying compiling services. Optionally the default current AppDomain assemblies can be referenced automatically with . if set to true the default assemblies of the current AppDomain will be referenced (see method). The freshly initialized instance of the . Clones the parent . This method returns a freshly initialized copy of the . The cloning 'depth' can be controlled by the . This method is a convenient technique when multiple instances are required (e.g. for concurrent script evaluation). if set to true all referenced assemblies from the parent will be referenced in the cloned copy. The freshly initialized instance of the . var eval1 = CSScript.Evaluator.Clone(); var eval2 = CSScript.Evaluator.Clone(); var sub = eval1.LoadDelegate<Func<int, int, int>>( @"int Sub(int a, int b) { return a - b; }"); var sum = eval2.LoadDelegate<Func<int, int, int>>( @"int Sub(int a, int b) { return a + b; }"); var result = sum(7, sub(4,2)); Enum for controlling concurrency in script hosting scenarios Any call to CSScript.Compile within a given process is synchronized Any call to CSScript.Compile a specific script within a given process is synchronized Any call to CSScript.Compile a specific script is synchronized system wide This class encapsulates another object for the purpose of passing it to the anonymous methods as parameters. This lass helps to overcome the problem when struct or immutable types cannot be passed to the anonymous methods with the ref modifier. The following is the example of the updating the local variable of a value type from the anonymous method: var count = new Ref<int>(1); Action<Ref<int>> increment = arg => { arg.Value += 1; }; increment(count); Type of the encapsulated object. Initializes a new instance of the class. The object to be encapsulated. Gets or sets the value of the encapsulated object. The value. Returns a that represents encapsulated object. A that represents encapsulated object. Class for automated assembly probing. It implments extremely simple ('optimistic') probing algorithm. At runtime it attempts to resolve the assemblies via AppDomain.Assembly resolve event by looking up the assembly files in the user dfined list of probing direcctories. The algorithm relies on the simple relationship between assembluy name and assembly file name: <assembly file> = <asm name> + ".dll" The following is an example of automated assembly probing. using (SimpleAsmProbing.For(@"E:\Dev\Libs", @"E:\Dev\Packages")) { dynamic script = CSScript.Load(script_file) .CreateObject("Script"); script.Print(); } Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. Releases unmanaged and - optionally - managed resources. true to release both managed and unmanaged resources; false to release only unmanaged resources. Finalizes an instance of the class. Initializes a new instance of the class. Creates and initializes a new instance of the class. The probing dirs. Initializes a new instance of the class. The probing dirs. Sets probing dirs and subscribes to the event. The probing dirs. Unsubscribes to the event. Simple helper class for extending functionality of . This class mainly consist of the extension methods for and it is to be used for executing the arbitrary code routines in the separate (temporary) with the optional unloading. This class is particularly useful for executing the CS-Script script in the separate as this is the only way to unload the script assembly after the execution (known .NET limitation). The following are the examples of the execution CS-Script scripts and unloading them after the execution: AppDomain.CurrentDomain .Clone() .Execute(Job) .Unload(); ... void Job() { var script = CSScript.LoadMethod("some C# script code") .GetStaticMethod(); script(); }; AppDomain remote = AppDomain.CurrentDomain.Clone(); remote.Execute(() => { var Sum = CSScript.BuildEval(@"func(float a, float b) { return a + b; }"); var Average = CSScript.BuildEval(@"func(float a, float b) { return (a + b)/2; }"); Console.WriteLine("Sum = {0}\nAverage={1}", Sum(1f, 2f), Average(1f, 2f)); }); remote.Unload(); The functionality of this class is very similar to the , which also allows executing and unloading the script(s). However is designed as a generic class and as such it is more suitable for executing a "job" routines instead of individual scripts. This creates some attractive opportunities for grouping scripting routines in a single , which allows simple calling conventions (e.g. CSScript.Load() instead of CSScript.Compile()) lighter type system (e.g. no need for MarshalByRefObject inheritance). Executes the delegate in the specified . The following are the examples of the execution CS-Script scripts and unloading them after the execution: var remoteDomain = AppDomain.CurrentDomain.Clone(); remoteDomain.Execute(Job) remoteDomain.Unload(); ... void Job() { var script = CSScript.LoadMethod("some C# script code") .GetStaticMethod(); script(); } The the delegate should be executed in. The delegate. The assembly probing directories of the AppDomain. Reference to the . It is the same object, which is passed as the . Executes the delegate in the specified . This method is allows you to pass the execution context parameter of the T type. Note T type must be serializable or inherited from MarshalByRefObject. This technique allows using AppDomain-neutral anonymous methods, which do not directly reference any variables from the primary AddDomain and yet allow interacting with this domain through the context parameter. The following is the example of the updating the primary AppDomain local variable foo from the routine executed in the remote domain: var foo = new Ref<string>("foo"); AppDomain.CurrentDomain .Clone() .Execute(context => { context.Value = "FOO"; }, context:foo) .Unload(); Note that the example is using type to to allow custom boxing. This is because the anonymous methods do not allow ref/out parameter modifiers. The the delegate should be executed in. The delegate. The context data. Note the type of this parameter must be either serializable or inherited from MarshalByRefObject . The assembly probing directories of the AppDomain. Reference to the . It is the same object, which is passed as the . Executes the delegate in the temporary with the following unloading of this domain. The following code the complete equivalent implementation of the ExecuteAndUnload: AppDomain.CurrentDomain .Clone() .Execute(action) .Unload(); The delegate to be executed. Unloads the specified . The to be unloaded. Clones the specified . The mandatory "creation" properties of the are used to create the new instance of . The "friendly name" of the cloned is a string representation of the random GUID. The to be cloned. The newly created . Gets the strong name of the assembly. The assembly. Assembly strong name. Gets the original location of the script that the assemble been compiled from. The assembly. Gets the name of the directory from the specified path. The path. Clones the specified . The mandatory "creation" properties of the are used to create the new instance of . The parameter is used as the "friendly name" for the cloned . The to be cloned. The "friendly name" of the new to be created. The permissions. The fully trusted assemblies. The newly created . Simple security helper class. This class is nothing else but a syntactic sugar. The following is an example of execution under .NET sandbox: Sandbox.With(SecurityPermissionFlag.Execution) .Execute(() => { //call sandboxed actions }); Generic void/void delegate Extension method. To assist with Fluent API. The object that is a subject of Fluent invocation. The action to be performed against object. Extension method. Executes with the specified array of permissions The permissions set to be used for the execution. The action to be executed. Returns the specified permissions as to be used with . The permissions. instance. Returns the specified permissions as to be used with . The permissions flag. Can be combination of multiple values. instance. Delegate to handle output from script Delegate to determine if the script assembly is out of data and needs to be recompiled The script source. The script assembly. 'true' if the script assembly is out of date. Type of the build (compile) configuration The typical Debug build configuration The typical Release build configuration A wrapper class that encapsulates the functionality of the Mono.CSharp.Evaluator. Clones itself as . This method returns a freshly initialized copy of the . The cloning 'depth' can be controlled by the . This method is a convenient technique when multiple instances are required (e.g. for concurrent script evaluation). if set to true all referenced assemblies from the parent will be referenced in the cloned copy. The freshly initialized instance of the . var eval1 = CSScript.MonoEvaluator.Clone(); var eval2 = CSScript.MonoEvaluator.Clone(); var sub = eval1.LoadDelegate<Func<int, int, int>>( @"int Sub(int a, int b) { return a - b; }"); var sum = eval2.LoadDelegate<Func<int, int, int>>( @"int Sub(int a, int b) { return a + b; }"); var result = sum(7, sub(4,2)); Gets or sets the compiler settings. The compiler settings. Gets or sets the compiling result. The compiling result. Gets or sets the flag indicating if the compilation error should throw an exception. The throw on error. Gets or sets the flag indicating if the script code should be analyzed and the assemblies that the script depend on (via '//css_...' and 'using ...' directives) should be referenced. Gets or sets a value indicating whether to reset Mono.Evaluator automatically after it fails to compile the code. It is a work around for the Mono.Evaluator (v4.0.0.0), which cannot longer compile the valid C# code after the first compilation failure. This setting allows auto recreation (reset) of the actual Mono.Evaluator service. true if Mono.Evaluator is to be reset automatically; otherwise, false. Gets or sets the warnings as errors. The warnings as errors. Initializes a new instance of the class. Gets or sets the flag for defining the conditional compiling symbol "DEBUG". The flag indicating if the "DEBUG" symbol defined. Gets or sets the build configuration. The configuration value. Gets or sets a value indicating whether to compile script with debug symbols. Note, affect of setting DebugBuild will always depend on the compiler implementation: CodeDomFully supports. Generates degugging symbols (script can be debugged) and defines DEBUG and TRACE conditional symbols MonoPartially supports. Defines DEBUG and TRACE conditional symbols RoslynDoesn't supports at all. true if 'debug build'; otherwise, false. Gets or sets the flag for defining the conditional compiling symbol "TRACE". The flag indicating if the "TRACE" symbol defined. Resets Evaluator. Resetting means clearing all referenced assemblies, recreating , and underlying compiling services. Optionally the default current AppDomain assemblies can be referenced automatically with . if set to true the default assemblies of the current AppDomain will be referenced (see method). The freshly initialized instance of the . The delegate for creating Mono compiler settings instance (). The delegate is a convenient way to specify global defaults for compiler settings. MonoEvaluator.CreateCompilerSettings = () => new CompilerSettings {Unsafe = true }; The name prefixes of the assemblies that will be ignored when and references the loaded assemblies of the current AppDomain. References the assemblies the are already loaded into the current AppDomain. The type of assemblies to be referenced. The instance of the to allow fluent interface. References the given assembly by the assembly path. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The path to the assembly file. The instance of the to allow fluent interface. References the given assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The assembly instance. The instance of the to allow fluent interface. References the name of the assembly by its partial name. Note that the referenced assembly will be loaded into the host AppDomain in order to resolve assembly partial name. It is an equivalent of Evaluator.ReferenceAssembly(Assembly.LoadWithPartialName(assemblyPartialName)) Partial name of the assembly. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. The namespace. Set to true if the namespace was successfully resolved (found) and the reference was added; otherwise, false. The instance of the to allow fluent interface. References the assembly by the given namespace it implements. Adds assembly reference if the namespace was successfully resolved (found) and, otherwise does nothing The namespace. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The object, which belongs to the assembly to be referenced. The instance of the to allow fluent interface. References the assemblies from the script code. The method analyses and tries to resolve CS-Script directives (e.g. '//css_ref') and 'used' namespaces based on the optional search directories. The script code. The assembly search/probing directories. The instance of the to allow fluent interface. References the assembly by the object, which belongs to this assembly. It is safe to call this method multiple times for the same assembly. If the assembly already referenced it will not be referenced again. The type which is implemented in the assembly to be referenced. The instance of the to allow fluent interface. Returns set of referenced assemblies. Notre: the set of assemblies is get cleared on Reset. Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. The following is the simple example of the LoadCode usage: dynamic script = CSScript.MonoEvaluator .LoadCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = script.Sum(1, 2); The C# script text. The non default constructor arguments. Instance of the class defined in the script. Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. The following is the simple example of the interface alignment: dynamic script = CSScript.MonoEvaluator .LoadFile("calc.cs"); int result = script.Sum(1, 2); /// The C# script file. Instance of the class defined in the script file. Evaluates and loads C# code to the current AppDomain. Returns instance of the first class defined in the code. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: Because the interface alignment is a duck typing implementation the script class doesn't have to inherit from T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.MonoEvaluator .LoadCode<ICalc>(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. The non default type T constructor arguments. Aligned to the T interface instance of the class defined in the script. Gets referenced assemblies from the script code. The script code. The assembly search/probing directories. Array of the referenced assemblies Evaluates and loads C# code from the specified file to the current AppDomain. Returns instance of the first class defined in the script file. After initializing the class instance it is aligned to the interface specified by the parameter T. Note: the script class does not have to inherit from the T parameter as the proxy type will be generated anyway. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); } .... ICalc calc = CSScript.MonoEvaluator .LoadFile<ICalc>("calc.cs"); int result = calc.Sum(1, 2); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the class defined in the script file. Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads (returns instance) the class to the current AppDomain. The following is the simple example of the LoadMethod usage: dynamic script = CSScript.MonoEvaluator .LoadMethod(@"int Product(int a, int b) { return a * b; }"); int result = script.Product(3, 2); The C# script text. Instance of the first class defined in the script. Wraps C# code fragment into auto-generated class (type name Scripting.DynamicClass), evaluates it and loads (returns instance) the class to the current AppDomain. After initializing the class instance it is aligned to the interface specified by the parameter T. The following is the simple example of the interface alignment: public interface ICalc { int Sum(int a, int b); int Div(int a, int b); } .... ICalc script = CSScript.MonoEvaluator .LoadMethod<ICalc>(@"public int Sum(int a, int b) { return a + b; } public int Div(int a, int b) { return a/b; }"); int result = script.Div(15, 3); The type of the interface type the script class instance should be aligned to. The C# script text. Aligned to the T interface instance of the auto-generated class defined in the script. Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns non-typed for class-less style of invoking. var log = CSScript.MonoEvaluator .CreateDelegate(@"void Log(string message) { Console.WriteLine(message); }"); log("Test message"); The C# code. The instance of a non-typed Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns typed for class-less style of invoking. The delegate return type. var product = CSScript.MonoEvaluator .CreateDelegate<int>(@"int Product(int a, int b) { return a * b; }"); int result = product(3, 2); The C# code. The instance of a typed Wraps C# code fragment into auto-generated class (type name DynamicClass), evaluates it and loads the class to the current AppDomain. Returns instance of T delegate for the first method in the auto-generated class. var Product = CSScript.MonoEvaluator .LoadDelegate<Func<int, int, int>>( @"int Product(int a, int b) { return a * b; }"); int result = Product(3, 2); The C# code. Instance of T delegate. Wraps C# code fragment into auto-generated class (type name DynamicClass) and evaluates it. This method is a logical equivalent of but is allows you to define your script class by specifying class method instead of whole class declaration. dynamic script = CSScript.MonoEvaluator .CompileMethod(@"int Sum(int a, int b) { return a+b; }") .CreateObject("*"); var result = script.Sum(7, 3); The C# code. The compiled assembly. Gets a type from the last Compile/Evaluate/Load call. The type name. The type instance Evaluates (compiles) C# code (script). The C# code is a typical C# code containing a single or multiple class definition(s). Assembly asm = CSScript.MonoEvaluator .CompileCode(@"using System; public class Script { public int Sum(int a, int b) { return a+b; } }"); dynamic script = asm.CreateObject("*"); var result = script.Sum(7, 3); The C# script text. The compiled assembly. Evaluates the specified C# statement and returns the result of the execution. string upperCaseText = (string)CSScript.MonoEvaluator.Evaluate("\"Hello\".ToUpper();"); int sum = (int)CSScript.MonoEvaluator.Evaluate("1+2;"); The C# statement. Result of the evaluation (execution). Evaluates the specified C# statement. The statement must be "void" (returning no result). CSScript.MonoEvaluator.Run("using System;"); CSScript.MonoEvaluator.Run("Console.WriteLine(\"Hello World!\");"); The C# statement. Gets the underlying .It is the actual Mono "compiler as service". Instance of . Custom implementation of required by API model for handling (reporting) compilation errors. default compiling error reporting (e.g. ) is not dev-friendly, thus CompilingResult is acting as an adapter bringing the Mono API close to the traditional CodeDOM error reporting model. The collection of compiling errors. The collection of compiling warnings. Indicates if the last compilation yielded any errors. If set to true indicates presence of compilation error(s). Indicates if the last compilation yielded any warnings. If set to true indicates presence of compilation warning(s). Creates the containing combined error information. Optionally warnings can also be included in the exception info. The flag indicating if compiler warnings should be included in the error () info. Instance of the . Clears all errors and warnings. Handles compilation event message. The compilation event message. if set to true [show full path]. A utility class which converts an object to specified interface T. The object does not necessarily need to implement the interface formally. Interface definition to convert to. Class Information: Authors: Ruben Hakopian March 2009 http://rubenhak.com/?p=167 Represents a map from a object type to the type of its proxy class. Converts specified object to an another object which implements interface T. The object to convert. The string array containing file names to the additional dependency assemblies the interface depends in. Converted object if succeeded; null otherwise. Checks if the source type can be convert to destination interface type. The source type to convert from. The destination interface type to convert to. The string array containing file nemes to the additional dependency assemblies the interface depends in. true if conversion can be performed; false otherwise Creates an instance of an proxy object which implements interface T and wraps specified object. Type of the interface. The object to convert. The string array containing file names to the additional dependency assemblies the interface depends in. Instance of the proxy object. Builds the proxy class for specified interface and source types. Type of the interface. Type of the source. if set to true the CSScriptLibrary.DynamicTypes will be injected the proxy class name. The string array containing file names to the additional dependency assemblies the interface depends in. Type definition for proxy class. Added by Oleg Shilo Generates the proxy class. Type of the interface. Type of the source. if set to true the CSScriptLibrary.DynamicTypes will be injected the proxy class name. Generates the proxy class properties. The generated class. Type of the interface. Type of the source. Generates the proxy class methods. The generated class. Type of the interface. Type of the source. Generates the proxy class events. The generated class. The generated class constructor. Type of the interface. Type of the source. Method extensions for Determines whether the specified assembly is a script assembly (compiled script) and returns full path of the script file used to compile the assembly. The analysis is based on the fact that script assembly (in hosing scenarios) is always stamped with , which contains name of the script file the assembly was compiled from. The format of the description The assembly. Script file path if the specified assembly is a script assembly otherwise null. Executes an action as a "singleton". This extension method takes a delegate and executes it in the context of the claimed named mutex. It doesn't execute the action and returns immediately if any previously invoked action from the same context is still in progress: mutex is not released. Mutex name uniqueness is based on the assembly identity (location). //application class Program { static void Main() { Assembly.GetExecutingAssembly() .SingletonExecute(main, ()=>MessageBox.Show("Another instance is already running.")); } static void main() { //business logic } } //script var script = @"using System.Reflection; public static void DoWork() { Assembly.GetExecutingAssembly() .SingletonExecute(() => { //business logic; }, () => Console.WriteLine(""another instance of 'script' is being executed"")); }"; var DoWork = CSScript.LoadMethod(script).GetStaticMethod(); Task.Run(DoWork); Task.Run(DoWork); Task.Run(DoWork); The assembly. The action. The on busy action. Constructs and returns an instance of CSScriptLibrary.AsmHelper class from the underlying Assembly. CSScriptLibrary.AsmHelper Instance of the type to be extended CSScriptLibrary.AsmHelper Returns which emitted delegate based on MethodInfo of the underlying assembly. Instance of the type to be extended 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or even *.*). List of 'Method' arguments. Note that values of the items in the list do not have any importance. The type of the list item is to be used for method search. For example if class Calc has method Sum(int a, int b) the method invoker can be obtained as following: GetStaticMethod("Calc.Sum", 0, 0) You can pass any integer as the second and third parameter because it will be used only to obtain the information about the parameter type (in this case System.Int32). Returns delegate of CSScriptLibrary.MethodDelegate type. Returns which emitted delegate based on MethodInfo of the underlying assembly. The delegate return type. Instance of the type to be extended 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or even *.*). List of 'Method' arguments. Note that values of the items in the list do not have any importance. The type of the list item is to be used for method search. For example if class Calc has method Sum(int a, int b) the method invoker can be obtained as following: GetStaticMethod("Calc.Sum", 0, 0) You can pass any integer as the second and third parameter because it will be used only to obtain the information about the parameter type (in this case System.Int32). Returns delegate of CSScriptLibrary.MethodDelegate type. Returns which emitted delegate based on MethodInfo of the underlying assembly. Instance of the type to be extended 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or even *.*). List of 'Method' arguments. Returns delegate of CSScriptLibrary.MethodDelegate type. Returns which emitted delegate based on MethodInfo of the underlying assembly. The delegate return type. Instance of the type to be extended 'Method' name including 'Type' name (eg. MyType.DoJob). It is allowed to use wild card character to indicate that the Type name of the method is irrelevant (e.g. "*.Method" or even *.*). List of 'Method' arguments. Returns delegate of CSScriptLibrary.MethodDelegate type. Instance of the type to be extended Specialized version of GetMethodInvoker which returns MethodDelegate of the very first method found in the underlying assembly. This method is an overloaded implementation of the GetStaticMethod(string methodName, params object[] list). Use this method when script assembly contains only one single type with one method. Returns delegate of CSScriptLibrary.MethodDelegate type. Instance of the type to be extended Specialized version of GetMethodInvoker which returns MethodDelegate of the very first method found in the underlying assembly. This method is an overloaded implementation of the GetStaticMethod(string methodName, params object[] list). Use this method when script assembly contains only one single type with one method. The delegate return type. Returns delegate of CSScriptLibrary.MethodDelegate type. Attempts to create instance of a class from underlying assembly. Instance of the type to be extended The 'Type' full name of the type to create. (see Assembly.CreateInstance()). You can use wild card meaning the first type found. However only full wild card "*" is supported. Instance of the 'Type'. Returns null if the instance cannot be created. Creates instance of a class from underlying assembly. Instance of the type to be extended The 'Type' full name of the type to create. (see Assembly.CreateInstance()). You can use wild card meaning the first type found. However only full wild card "*" is supported. The non default constructor arguments. Instance of the 'Type'. Throws an ApplicationException if the instance cannot be created. Creates the instance of the Type. It is nothing else but a more convenient version of Assembly. CreateInstance(string typeName, bool ignoreCase, BindingFlags...) method. It's objective is to simplify invoking the constructors with parameters. The assembly. Name of the type. The arguments. Extends the life of the instance created in the remote AppDomain. The instance created in the remote AppDomain. The renewal time. Returns object. Extends the life of the instance created in the remote AppDomain. The instance created in the remote AppDomain. The renewal time in minutes. Returns object. Extends the life of the instance created in the remote AppDomain. The delegate return type. The instance of the created in the remote AppDomain. The renewal time in minutes. Returns object. MethodDelegate doesn't seem to be owned by the transparent proxy connected to the remote AppDomain object. + You don't need to extend life local objects. Extends the life of the instance created in the remote AppDomain. The instance of the created in the remote AppDomain. The renewal time in minutes. Returns object. MethodDelegate doesn't seem to be owned by the transparent proxy connected to the remote AppDomain object. + You don't need to extend life local objects. Attempts to align (pseudo typecast) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. Interface object or null if alignment was unsuccessful. Attempts to align (pseudo typecast) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. If set to true uses all loaded assemblies of the current when emitting (compiling) aligned proxy object. Interface object or null if alignment was unsuccessful. Attempts to align (pseudo typecast) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. The string array containing file nemes to the additional dependency assemblies the interface depends in. Interface object or null if alignment was unsuccessful. Attempts to align (pseudo typecast) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. If set to true uses all loaded assemblies of the current when emitting (compiling) aligned proxy object. The string array containing file names to the additional dependency assemblies the interface depends in. Interface object or null if alignment was unsuccessful. Aligns (pseudo typecasts) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. If set to true uses all non-GAC loaded assemblies of the current when emitting (compiling) aligned proxy object. Interface object. Aligns (pseudo typecasts) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. The string array containing file names to the additional dependency assemblies the interface depends in. Interface object. Aligns (pseudo typecasts) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. If set to true uses all non-GAC loaded assemblies of the current when emitting (compiling) aligned proxy object. The string array containing file names to the additional dependency assemblies the interface depends in. Interface object. Aligns (pseudo typecasts) object to interface. The object does not necessarily need to implement the interface formally. See . Interface definition to align with. The object to be aligned with the interface. Interface object.