I am trying to pass a delegate type as a type parameter so that I can use it later as a type parameter in the code, for example:
// Definition private static class Register { public static FunctionObject Create<T>(CSharp.Context c, T func) { return new IronJS.HostFunction<T>(c.Environment, func, null); } } // Usage Register.Create<Func<string, IronJS.CommonObject>>(c, this.Require);
However, the C # compiler complains:
The type 'T' cannot be used as type parameter 'a' in the generic type or method 'IronJS.HostFunction<a>'. There is no boxing conversion or type parameter conversion from 'T' to 'System.Delegate'."
I tried to fix this by adding the "where T: System.Delegate" function to the function, however you cannot use System.Delegate as a restriction on type parameters:
Constraint cannot be special class 'System.Delegate'
Does anyone know how to resolve this conflict?
DOES NOT WORK (information of type Argument and return type is lost during translation):
Delegate d = (Delegate)(object)(T)func; return new IronJS.HostFunction<Delegate>(c.Environment, d, null);
June Rhodes
source share