c# - Grabbing, storing and using all interfaces in the solution, when the interfaces are <T> -


stumped on one. had method:

private static list<ibiscuittransformer> getbiscuittransformers()  {      var type = typeof(ibiscuittransformer);      var transformers = appdomain.currentdomain.getassemblies()          .selectmany(s => s.gettypes().where(c => !c.isinterface))          .where(p => type.isassignablefrom(p))          .select(c => (ibiscuittransformer)activator.createinstance(c))          .tolist();       return transformers;  } 

this worked great. had several implementations of biscuittransformer, , biscuity goodness.

however, problem want ibiscuittransformer have method takes in list<t> biscuitbarrelbiscuits parameter. seems force me make ibiscuittransformer ibiscuitstransformer<t>, don't want, may unavoiable.

once this, don't know how modify above code can create instance of classes implement ibiscuittransformer<t>. possibly because don't know t? or can't figure out syntax. shouldn't need know t create instance, it's method call want take in t. method on objects transformbiscuit(list<t> biscuitbarrelbiscuits) want generic, not class itself, should possible create instance of activator.

but can't figure out how it, or if it's possible. ideas?

just explain trying do, have bunch of biscuit transformers take in biscuits , transform them. there 1 each type of biscuit, , load them via reflection array can choose 1 use when biscuit comes in. transformers have common interface, transformbiscuit method on them, because take in collection of different types of biscuit, has list in order them able use same interface.

i'm not sure if can't figure out concept or if i'm fundamentally doing wrong.

make method generic.

void transformbiscuit<t>(list<t> biscuitbarrelbiscuits) 

this assuming single instance of biscuittransformer able transform top of biscuits pass in, of course.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -