Использование делегата для обработки обратного вызова Javascript в JINT - PullRequest
0 голосов
/ 16 июня 2019

В следующем коде, использующем JINT, вызов метода Setup1 работает, а вызов метода Setup2 - нет. При вызове Setup2 возникает ошибка: Jint.Runtime.JavaScriptException: «Не найдено открытых методов с указанными аргументами.»

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; })");
        }
    }
}

Так почему же сбой вызова Setup2? Чем отличается Func от делегата DoFunction ()?

...