I have been testing the jint library and hit a snag. Given this class in C#:
public class Foo
{
public string Name { get; } = "Bar";
}
And this code:
Engine engine = new Engine(x => x.AllowClr());
object rc = _engine
.SetValue("foo", new Foo())
.Execute("foo.Name.startsWith('B')")
.GetCompletionValue()
.ToObject();
I get the error: 'Jint.Runtime.JavaScriptException: 'Object has no method 'startsWith'''
This works, however:
"foo.Name == 'Bar'"
So can I get the former to work?
Support for extension methods is added here. But can't get it to work with the .NET string extension methods directly, it does work with an intermediate extensions class.
Update: The string methods like
StartsWith
aren't real extension methods indeed.Looks like startsWith is already supported natively now. Replaced
GetCompletionValue
with the suggestedEvaluate
I've tried to add the
string
extension methods, but that doesn't seem to work. But using your own class for the extension methods and use it that way does work.I've asked about the native extension methods support here, as I'm curious if and how it is supposed to work.