I want to overload operator +(f,s) for a generic class. It should return +(f,s) if f and s have plus operator and null otherwise. How can I do it?
public class param<T> : TDefault
{
public string param_name;
public T cnt;
public param(T _cnt)
{
cnt=_cnt;
}
public static param<T> operator +(param<T> f, param<T> s)
{
if(T ? has_operator("+"))
return param<T>(((f.cnt as ?)+(s.cnt as ?)) as T);
return null;
}
}
For checking operator existence I tried
public static bool has_method(this object target,string method_name)
{
return target.GetType().GetMethod(method_name)!=null;
}
but
int x;
print (x.has_method("+="));
prints 'false'