 | RoslynEvaluatorLoadMethodT Method (String) |
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.
Namespace:
CSScriptLib
Assembly:
CSScriptLib (in CSScriptLib.dll) Version: 1.3.2.0
Syntaxpublic T LoadMethod<T>(
string code
)
where T : class
Parameters
- code
- Type: SystemString
The C# script text.
Type Parameters
- T
- The type of the interface type the script class instance should be aligned to.
Return Value
Type:
TAligned to the
T interface instance of the auto-generated class defined in the script.
Implements
IEvaluatorLoadMethodT(String)
ExamplesThe 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);
See Also