开发者

Is it possible to invoke a delegate in monotouch?

开发者 https://www.devze.com 2023-02-08 20:55 出处:网络
I have the following using System; namespace mtSpec { public class SpecElement { public SpecElement (Delegate action, string name)

I have the following using System;

namespace mtSpec
{
    public class SpecElement
    {
        public SpecElement (Delegate action, string name)
        {
            Name = name;
            this.ActionToTake = action;
        }

        public Delegate ActionToTake {get; set;}
开发者_如何学Go        public string Name {get; set; }

        public bool Execute()
        {
            try {
                 this.ActionToTake.DynamicInvoke();
                return true;
            } catch (Exception ex) {
                return false;
            }
        }
    }
}

Calling Execute always causes the following at the point of DynamicInvoke():

  • Assertion: should not be reached at ../../../../mono/mini/debugger-agent.c:3092

Am I missing something? How can I invoke my delegate please?

Escoz? Miguel? Anyone?


You can just write

something();


Instead of Delegate I would use Action. No need to call DynamicInvoke.

public class SpecElement
{
    public SpecElement (Action action, string name)
    {
      Name = name;
    this.ActionToTake = action;
  }

    public Action ActionToTake {get; set;}
    public string Name {get; set; }

  public bool Execute()
    {
      try 
      {
       this.ActionToTake();
         return true;
      } 
      catch (Exception) 
      {
         return false;
      }
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号