Start a new topic

new Action vs just delegate of action

 When using actions to map to javascript function like so:

WHERE obj.func = Action();


obj.func = () => { console.log('got here'); }


sometimes does not work get delegate not found


but if i go:


obj.func = new Action(()=>{ console.log('Got here'); });


that DOES WORK.


Why do i have to sometimes use new Action vs just the delegate like you do in so many samples



I think the problem my be when the invoke action function takes a delegate instead of an action. Example: [Js(Extern=true)] Public Extern void somemethod (Delegate fn); Only works when actually calling with new Action, the other ways give an error... I'm Kool with the new, just wanted to know if there was a difference or penalty for always using 'new' Action to wrap js functions

In C# all these are semantically the same, and we even have tests for these 3 cases in DuoCode:

   

[Test]
public void Invokes2()
{
  int i = 0;

  InvokeAction(() => { ++i; });
  QUnit.AreEqual(i, 1);

  InvokeAction((Action)(() => { ++i; }));
  QUnit.AreEqual(i, 2);

  InvokeAction(new Action(() => { ++i; }));
  QUnit.AreEqual(i, 3);
}

private static void InvokeAction(Action action)
{
  action();
} 

   

Can you explain what error do you have?

Login or Signup to post a comment