Getting all object properties with an associated type converter

G

Guest

Hi
I have a class which has its own type converter that adds some additional
properties using overridden GetPropertiesSupported and GetProperties methods.
All works fine if an instance of the class is set as the selected object in
a property grid. However in code I would like to make a call such as
myclassInstance.GetType().GetProperties() which returns all the properties
including the ones added via the associated type converter. Currently I only
get the properties "hard-wired" in the class. Is such a thing possible?

Thanks for any help anyone can provide.

Marek
 
L

Linda Liu [MSFT]

Hi Marek,

When the Type.GetProperties method is called, system will get the
properties of the specified type through reflection, which means only the
inherent properties contained in the meta data of the type are returned.

A simple workaround to your problem is to call the GetProperties method
within the type converter explicitly. The following is a sample. It
requires that you pass an instance of your class to the GetProperties
method.

PropertyDescriptorCollection pdc =
TypeDescriptor.GetConverter(typeof(YourClass)).GetProperties(instanceofyourc
lass);

In fact, a common usage to extend the meta data of a type is to implement
Interface ICustomTypeDescriptor or add a custom TypeDescriptionProvider for
the type. After doing that, call the following statements to get what you
want:

// if you implement ICustomTypeDescriptor for the type, or add a custom
TypeDescriptionProvider on the type
PropertyDescriptorCollection pdc
=TypeDescriptor.GetProperties(instanceofyourclass);

// if you add a custom TypeDescriptionProvider on the type
PropertyDescriptorCollection pdc
=TypeDescriptor.GetProperties(typeof(YourClass));

Hope this helps.
If you have any question, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top