I'm trying to execute a script dynamically, via CSharpScript
, following the example here:
example
public class Feature
{
public class Params
{
public TypeA ParamA { get; set; }
public TypeB ParamB { get; set; }
}
public static TypeA paramA;
public static TypeB paramB;
public ExecuteScript(foo, bar)
{
paramA = GetParameterA(foo);
paramB = GetParameterB(paramA, bar);
string scriptCommand = @"
function1(paramA)
... // do stuff
return ""done"";
";
var options = ScriptOptions.Default
.WithImports(
"System",
"System.Collections.Generic",
"System.Linq",
);
var items = new Params()
{
ParamA = paramA,
ParamB = paramB
};
var result = CSharpScript.EvaluateAsync<string>(scriptCommand, options, globals: items).Result;
}
}
Nevertheless, when running the script, I'm getting an error:
error CS0103: The name 'paramB' does not exist in the current context
Any idea what I'm doing wrong? I'm guess it's something to do with the nested Class definition but not sure exactly what I'm missing here :/
EDIT:
When using local variables in the scope of the ExecuteScript()
method
TypeA paramA;
TypeB paramB;
and then using them in result:
var result = CSharpScript.EvaluateAsync<string>(scriptCommand, options, globals: new { paramA, paramB }).Result;
The error for the var result
line is different and is:
error CS0122: '<>f__AnonymousType0<paramA, paramB>.paramB' is >inaccessible due to its protection level