2

In the following code using JINT, the call to the Setup1 method works and the call to Setup2 method does not. The call to Setup2 raises the error: Jint.Runtime.JavaScriptException: 'No public methods with the specified arguments were found.'

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    public delegate bool DoFunction();

    public class TestClass
    {
        public TestClass() { }

        public void Setup1(Func<bool> fn)
        {
            bool b = fn();
        }

        public void Setup2(DoFunction fn)
        {
            bool b = fn();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Jint.Engine _engine = new Jint.Engine();
            _engine.SetValue("test", new TestClass());
            _engine.Execute("test.Setup1(function() { return true; })");
            _engine.Execute("test.Setup2(function() { return true; })");
        }
    }
}

So why does the call to Setup2 fail? What is the different between Func and the delegate DoFunction()?

Ian Hannah
  • 131
  • 1
  • 1
  • 10

0 Answers0