c# - Call generic Method with multiple generic Types without specifying every single generic Type -
so have generic method multiple generic types.
now i'd call method way (using types of , b , specifying return type):
class example { t1 genericmethod<t1, t2, t3>(t2 parameter1, t3 parameter2) { t1 returnvalue = default(t1); // ... returntype, parameter1 , parameter2 return returnvalue; } void accessgenericmethod() { var = new foo1(); var b = new foo2(); var result = genericmethod<returntype>(a, b); // doesn't work } }
and avoid call genericmethod
way
var result genericmethod<returntype, foo1, foo2>(a, b);
in c#, there no partial type inference: must either specify or none of generic arguments, latter works if compiler able infer types context. return types cannot infered (except special cases such lambdas), want not possible.
two workarounds:
a: move t1
method class
class example<t1> { t1 genericmethod<t2, t3>(t2 parameter1, t3 parameter2)
b: replace t2
, t3
object
class example { t1 genericmethod<t1>(object parameter1, object parameter2)
Comments
Post a Comment