c# - Cannot convert from 'System.Type' to myself defined interface -
i defined own iexportable
interface, , use as
public static someaction<b>(ilist<t> data) t : iexportable { var ttype = typeof(t); ilist<b> blists = somemethod(ttype); //... }
that somemethod
is:
list<b> somemethod(iexportable exportdata) { // somethings }
but when run application error:
the best overloaded method match somemethod(iexportable)has invalid arguments cannot convert 'system.type' 'ifileexport'
mistake?
typeof(t)
returns type object has meta information class represented t
. somemethod
looking object extends iexportable
, want create object t
extends iexportable
. have few options this. straight forward option may add new
constraint on generic paramter , use t
's default constructor.
//notice i've added generic paramters , t. looks may //have missed adding parameters or have specified many types. public static someaction<a, b, t>(ilist<t> data) t : iexportable, new() { t ttype = new t(); ilist<b> blists = somemethod(ttype); //... }
i've explicitly stated type of ttype
better illustrate what's going on in code:
public static someaction<b>(ilist<t> data) t : iexportable { //notice typeof returns. system.type ttype = typeof(t); ilist<b> blists = somemethod(ttype); //... }
Comments
Post a Comment