c# - Passing Type as argument but constraining to interface -
i'm passing type
of object argument in constructor constrain type objects inherit specific interface.
public myclass(type mytype);
i know check type inherits interface in body of method so:
if(typeof(imyinterface).isassignablefrom(mytype))
but type constraint arguments possible?
why wouldn't make class generic? in case can specify constraint , not bother checking argument.
e.g.
public class myclass<t> t : imyinterface { .... }
Comments
Post a Comment