public void CompileMethod_Static()
{
// 1 - CompileMethod wraps method into a class definition and returns compiled assembly
// 2 - GetStaticMethod returns duck-typed delegate that accepts 'params object[]' arguments
// Note: GetStaticMethodWithArgs can be replaced with a more convenient/shorter version
// that takes the object instead of the Type and then queries objects type internally:
// "GetStaticMethod("*.Test", data)"
var test = CSScript.Evaluator
.CompileMethod(@"using CSScriptEvaluatorApi;
static void Test(InputData data)
{
data.Index = GetIndex();
}
static int GetIndex()
{
return Environment.TickCount;
}")
.GetStaticMethodWithArgs("*.Test", typeof(InputData));
var data = new InputData();
test(data);
}