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

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -