DynamicScriptExecutor 1.6.0
See the version list below for details.
dotnet add package DynamicScriptExecutor --version 1.6.0
NuGet\Install-Package DynamicScriptExecutor -Version 1.6.0
<PackageReference Include="DynamicScriptExecutor" Version="1.6.0" />
paket add DynamicScriptExecutor --version 1.6.0
#r "nuget: DynamicScriptExecutor, 1.6.0"
// Install DynamicScriptExecutor as a Cake Addin #addin nuget:?package=DynamicScriptExecutor&version=1.6.0 // Install DynamicScriptExecutor as a Cake Tool #tool nuget:?package=DynamicScriptExecutor&version=1.6.0
DynamicScriptExecutor
<img src="https://www.nuget.org/Content/gallery/img/logo-header.svg?sanitize=true" height="30px">
Enables exectime execution of C#/VB.NET scripts without pre-compilation. Supports Func delegate generation, DLLs, flexible exec options, and async capabilities.
Download
DynamicScriptExecutor is available as Nuget Package now.
Getting started
Hello World
string codeHelloWorld = @"
using System;
class Exec
{
public void Main()
{
Console.WriteLine(""Hello World"");
}
}
";
DynamicScriptExecutor.ScriptExecutor.Exec(codeHelloWorld); // Hello World
If you want to hold an InstanceObject
string codeStatic = @"
using System;
public static class Exec
{
public static int count = 1;
public static void Main()
{
Console.WriteLine(""Hello World Static: "" + count++);
}
}
";
ExecOption execOptionStatic = new ExecOption() { IsStatic = true };
execOptionStatic.InstanceObject = new InstanceObject(codeStatic, execOptionStatic);
ScriptExecutor.Exec(execOptionStatic); // Hello World Static: 1
ScriptExecutor.Exec(execOptionStatic); // Hello World Static: 2
If you want to create delegate
string codeDelegateHelloWorld = @"
using System;
public class Exec
{
public string DelegateHelloWorldFunc()
{
return ""Delegate Hello World"";
}
}
";
var DelegateHelloWorldFunc = DynamicScriptExecutor.ScriptExecutor.GenerateFunc<string>(codeDelegateHelloWorld, new ExecOption() { MethodName = "DelegateHelloWorldFunc" });
Console.WriteLine(DelegateHelloWorldFunc(null)); // Delegate Hello World
If you only want to write functions and don't want to write using statement
string codeGenerateClassWithFunction = @"
public ExternalResultClass DoSth()
{
return ExternalClass.DoSth();
}
";
ExecOption generateClassWithFunctionOption = new ExecOption();
generateClassWithFunctionOption.ExtraDllFileList = new List<string> { "ExternalDll.dll" };
generateClassWithFunctionOption.MethodName = "DoSth";
string codeGeneratedClassWithFunction = ScriptExecutor.GenerateClassWithFunction(codeGenerateClassWithFunction, generateClassWithFunctionOption);
API
ScriptExecutor
object Exec(string code, ExecOption execOption = null)
Task<object> ExecAsync(string code, ExecOption execOption = null)
object Exec(ICollection<string> codeList, ExecOption execOption = null)
Task<object> ExecAsync(ICollection<string> codeList, ExecOption execOption = null)
object Exec(ExecOption execOption)
Task<object> ExecAsync(ExecOption execOption)
Func<object[], object> GenerateFunc(string code, ExecOption execOption = null)
Func<object[], object> GenerateFunc(ExecOption execOption)
Func<object[], TResult> GenerateFunc<TResult>(string code, ExecOption execOption = null)
Func<object[], TResult> GenerateFunc<TResult>(ExecOption execOption)
Func<T1, TResult> GenerateFunc<T1, TResult>(string code, ExecOption execOption = null)
Func<T1, TResult> GenerateFunc<T1, TResult>(ExecOption execOption)
Func<T1, T2, TResult> GenerateFunc<T1, T2, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, TResult> GenerateFunc<T1, T2, TResult>(ExecOption execOption)
Func<T1, T2, T3, TResult> GenerateFunc<T1, T2, T3, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, TResult> GenerateFunc<T1, T2, T3, TResult>(ExecOption execOption)
Func<T1, T2, T3, T4, TResult> GenerateFunc<T1, T2, T3, T4, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, T4, TResult> GenerateFunc<T1, T2, T3, T4, TResult>(ExecOption execOption)
Func<T1, T2, T3, T4, T5, TResult> GenerateFunc<T1, T2, T3, T4, T5, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, T4, T5, TResult> GenerateFunc<T1, T2, T3, T4, T5, TResult>(ExecOption execOption)
Func<T1, T2, T3, T4, T5, T6, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, T4, T5, T6, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, TResult>(ExecOption execOption)
Func<T1, T2, T3, T4, T5, T6, T7, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, T4, T5, T6, T7, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, TResult>(ExecOption execOption)
Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(ExecOption execOption)
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, TResult>(ExecOption execOption)
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(string code, ExecOption execOption = null)
Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult> GenerateFunc<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TResult>(ExecOption execOption)
string GenerateClassWithFunction(string code, ExecOption execOption = null)
string GenerateClassWithFunction(string code, ICollection<string> extraDllNamespaces, ExecOption execOption = null)
DllHelper
FileSystemInfo[] GetDllInfos(string path)
ICollection<string> GetExtraDllNamespaces(ExecOption execOption)
InstanceObject
InstanceObject
InstanceObject(string code, ExecOption execOption = null)
InstanceObject(ICollection<string> codeList, ExecOption execOption = null)
Options
ExecOption
ExecOption(object[] paramList = null
, ICollection<string> extraDllFolderList = null
, ICollection<string> extraDllFileList = null
, string methodName = "Main"
, string className = "Exec"
, InstanceObject instanceObject = null
, ScriptLanguage scriptLanguage = ScriptLanguage.CSharp
, bool nonPublic = false
, bool isStatic = false
, bool addDefaultUsingWhenGeneratingClass = true
, bool addExtraUsingWhenGeneratingClass = true)
object[] paramList;
ICollection<string> extraDllFolderList;
ICollection<string> extraDllFileList;
string methodName;
string className;
InstanceObject instanceObject;
ScriptLanguage scriptLanguage;
bool nonPublic;
bool isStatic;
bool addDefaultUsingWhenGeneratingClass;
bool addExtraUsingWhenGeneratingClass;
ScriptLanguage
- CSharp
- VisualBasic
Useage
DynamicScriptExecutor.ExecOption execOption = new DynamicScriptExecutor.ExecOption(...);
DynamicScriptExecutor.ScriptExecutor.Exec(code, execOption);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.CodeAnalysis.CSharp (>= 4.4.0)
- Microsoft.CodeAnalysis.VisualBasic (>= 4.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.