c# - Type-safe collection of Type class with defined base type -
i'm use generic collection in code:
list<type> what want type-safe collection of types defined basetype
list<typeof(basetype)>, valid :)
you can't create type-safe collection of type objects describe types derive base type, because c#'s type-safe generic mechanism can operate on types known @ compile-time, while relationship between typeof(mybasetype) , typeof(myderivedtype) knowm @ runtime.
furthermore, have remember relationship between these type objects not relationship of inheritance. string may derive object, typeof(string) doesn't derive typeof(object). while relationship may seem relevant type-safety, isn't really.
a collection of type objects of subtypes of specific type equivalent, in terms of type safety, collection of even-numbered ints - has nothing type safety, , such difficult implement generics.
Comments
Post a Comment