Getting multiple attributes of same type from Property

Last post 08-27-2007 4:22 PM by Max Kukartsev. 1 replies.

Sort Posts:

  • Getting multiple attributes of same type from Property

    08-14-2007, 8:33 AM
    • Participant
      1,251 point Participant
    • awilinsk
    • Member since 08-12-2005, 2:01 PM
    • Posts 251

    I am writing code for a custom control. I have created a ConverterAttribute to convert the value in the property to something else. My CustomAttribute can be applied multiple times to a single property that allows conversion of a collection. Say I want to have a converter for the actual collection and a converter for the items in the collection, I need to get these two ConverterAttributes. How do you get an attribute array (CustomAttribute[]) from the PropertyDescriptor? I know you can do prop.Attributes[typeof(CustomAttribute)], but that only returns a single attribute and I need all of them on the property to build my object serializer.

    -wili
  • Re: Getting multiple attributes of same type from Property

    08-27-2007, 4:22 PM

    Hi.

    What exactly are you trying to do by applying more than one instance of the same attribute to a property? The code for doing that won't even compile. However theoretically if you do have multiple instances of the same attribute applied to a class or member, you can retrieve them through GetCustomAttributes(typeof(<custom attribute type>)) method of Type or MemberInfo. The Descriptor classes in System.ComponentModel are only components that utilize reflection through their various methods and properties.

    Hope this helps. 

Page 1 of 1 (2 items)