2
0

DelegateWrapper.cs 751 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using Jint.Native;
  3. using Jint.Native.Function;
  4. namespace Jint.Runtime.Interop
  5. {
  6. /// <summary>
  7. /// Represents a FunctionInstance wrapper around a CLR method. This is used by user to pass
  8. /// custom methods to the engine.
  9. /// </summary>
  10. public sealed class DelegateWrapper : FunctionInstance
  11. {
  12. private readonly Engine _engine;
  13. private readonly Delegate _d;
  14. public DelegateWrapper(Engine engine, Delegate d) : base(engine, null, null, false)
  15. {
  16. _engine = engine;
  17. _d = d;
  18. }
  19. public override JsValue Call(JsValue thisObject, JsValue[] arguments)
  20. {
  21. return JsValue.FromObject(_d.DynamicInvoke(arguments));
  22. }
  23. }
  24. }