是否可以在monotouch中调用委托?

时间:2011-02-04 21:27:26

标签: c# xamarin.ios

我有以下内容 使用System;

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

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

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

调用执行总是在DynamicInvoke()处产生以下内容:

  
      
  • 断言:不应该在../../../../ mono / mini / debugger-agent.c:3092
  • 上联系   

我错过了什么吗?我该如何调用我的代表?

Escoz?米格尔?任何人吗?

2 个答案:

答案 0 :(得分:2)

你可以写

something();

答案 1 :(得分:2)

而不是代表我会使用Action。无需调用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;
      }
   }
}
相关问题