Is it possible to invoke a delegate in monotouch?
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;
}
}
}
精彩评论