c# - Why is TypeDescriptor.GetProperties behaving different for types and objects when working with ICustomTypeDescriptor -
i created generic class group implements icustomtypedescriptor. adds properties of generic type parameter own properties.
private void initializedisplayedproperties() { _displayedproperties.add(typedescriptor.getproperties(typeof(group<t>))["lastitem"]); _displayedproperties.add(typedescriptor.getproperties(typeof(group<t>))["groupid"]); _displayedproperties.add(typedescriptor.getproperties(typeof(group<t>))["count"]); foreach (propertydescriptor mydescr in typedescriptor.getproperties(typeof(t))) { _displayedproperties.add(mydescr); } }
why following code behave different?
typedescriptor.getproperties(typeof(group<igroupedobject>)).count //returns 3 items of group typedescriptor.getproperties(new group<igroupedobject>()).count //returns 31 items of group , generic type parameter
i assume must have fact properties generated @ instance time of object. isn't number of attributes defined used types?
is possible work around behaviour without instantiating type?
i assume actual type implements icustomtypedescriptor
; if case, typedescriptor.getproperties(object)
api can access data, isn't willing create ad-hoc instance properties (and indeed, pretty common if type implements icustomtypedescriptor
, properties vary per instance, wouldn't useful anyway).
if want entire type support this, need create , register typedescriptionprovider
. works @ higher level, , allows custom properties apply type without needing consider instance. nice thing automatically apply lists etc, without needing implement itypedlist
.
so basically: research typedescriptionprovider
.
Comments
Post a Comment