[Mono-dev] Implicit Polymorphy Question
Robert Jordan
robertj at gmx.net
Thu Sep 22 12:45:49 EDT 2005
Samuel Abels wrote:
> Hello,
>
> Consider this class:
>
> -------------------------
> public class FuncCaller
> {
> public delegate void Function(object args);
> public Function function;
> public object args;
>
> public FuncCaller (Function function_, object args_)
> {
> function = function_;
> args = args_;
> }
>
> public void Call ()
> {
> if (!function || !args)
> return;
> function(args);
> }
> }
> -------------------------
>
> The above class is supposed to hold a function, including all arguments,
> and execute the call later.
> However, I am looking for a way to pass *any* type of argument to the
> constructor, rather then only variables of type "object". E.g.:
You're looking for something like that (untested):
class FuncCaller
{
Delegate d;
object[] args;
public FuncCaller (Delegate d, params object[] args)
{
this.d = d;
this.args = args;
}
public object Call ()
{
return d.DynamicInvoke (args);
}
}
Rob
More information about the Mono-devel-list
mailing list