There are a couple of options depending on which language(s) you want to support. VB Script can be done using MSScriptControl and C# can be done using Microsoft.CSharp.
Here's a quick example of something I just did to pull a C# script out of a database and execute it. Please note that this only takes in strings so you would have to adjust it if you wanted your arguments to be a collection or different data type.
value = CreateTransformMethodInfo(_script.ScriptBody).Invoke(null, args.Select(x => x.Value).ToArray()); //args would be the arguments in your script
public static MethodInfo CreateTransformMethodInfo(string script)
{
using (var compiler = new CSharpCodeProvider())
{
var parms = new CompilerParameters
{
GenerateExecutable = false,
GenerateInMemory = true,
CompilerOptions = "/optimize",
ReferencedAssemblies = { "System.Core.dll" }
};
return compiler.CompileAssemblyFromSource(parms, script)
.CompiledAssembly.GetType("Transform")
.GetMethod("Execute");
}
}
Then the actual script looks like this:
public class Transform
{
public static string Execute(string firstName)
{
return "Test";
}
}
The one caveat to this is that you would need to name the class 'Transform' and the method to run 'Execute' every time since you can see we use these two values when compiling the method to run. You could name helper classes or methods whatever you wanted though, as long as the 'executing' class and method stays Transform/Execute.