c# - define collection of a type that was retrieved by a method (no reflection) -
this question has answer here:
i have interface idomain
1 method gives me element type of domain:
interface idomain { type elementtype { get; } }
i want create collection of appropriate element type given idomain
. how do that?
the following not work:
idomain dom = ... // somewhere type elemtype = dom.elementtype; icollection<elemtype> mycoll = new hashset<elemtype>(); // error: "'elemtype' variable used type"
writing icollection<typeof(elemtype)>
not either.
it should noted dom.elementtype
can of type a
, b
or c
. know @ point of code, because wrote way.
is there other way achieve without using reflection?
Comments
Post a Comment