[Mono-dev] Implicit Polymorphy Question

Samuel Abels newsgroups at debain.org
Thu Sep 22 11:27:00 EDT 2005


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)

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.:

public myfunc1 (string str) { ... }
public myfunc2 (ArrayList lst) { ... }
FuncCaller caller1 = new FuncCaller(myfunc, "test");
FuncCaller caller2 = new FuncCaller(myfunc, myarraylist);

This produces errors like

Cannot convert implicitly from `object' to `System.Collections.ArrayList'

Of course, I could cast the value, but is there a way to make this work

I have only found the .NET 2.0 "generics" that might help, but
apparently Mono does not yet have support for them in regular releases
(though I found a note that it is available in CVS already).
Is there a (typesafe) way to accomplish something similar without using


More information about the Mono-devel-list mailing list