c# - Is it possible to have a Dictionary where the value for a given key/value pair is enforced to be of a specific type based on the key? -
specifically trying create dictionary keys of type propertyinfo , value list enforce containing objects of same type associated property described key. in other words, dictionary describes set of properties , values assign them.
i know can use list of objects, far can tell, forces me perform check validity of contained list types @ run-time , forces me check every member of list.
ideally, i'd instead enforced @ compile time rather run time and/or remove need verifying ever individual member of list. ok getting compile time error if compiler cannot determine property's type @ compile time (my particular use case deals properties known).
i suspect may not possible due issue of compiler not having way of type property have prior run time, i'm hoping missed may allow it.
you haven't missed anything. it's impossible since there no property type info associated propertyinfo
@ compile time. it's not generic type (like list<t>
).
wiki
Comments
Post a Comment