Replies: 1 comment
-
You can add instance of a type and static methods will be resolved. public class MathUtil
{
public double Max(int val1, int val2) => System.Math.Max(val1, val2);
}
public class StaticTest
{
[Fact]
public void ShouldBeAbleToExposeStaticMember()
{
var engine = new Engine();
engine.SetValue("MathUtil", new MathUtil());
Assert.Equal(2, engine.Evaluate("MathUtil.max(1, 2)"));
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use classes from an Assembly, specifically a class that has static functions that return objects.
In C# the classes methods could be referenced using MyBase.MyLibrary.MyClass
Tried using AllowClr( typeof( MyClass ).Assembly ) when I create the engine but executing this script:
fails with the error MyClass is not defined.
I'd like to setup a simple namespace as is done with the builtin Math functionality but the facilities used in that code are all internal. It seems unnecessarily difficult to do what I want so I must be doing things the wrong way.
Beta Was this translation helpful? Give feedback.
All reactions