Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: CategoryOrderAttribute not working as intended [21420]

$
0
0
The property grid ObjectContainerHelper class uses Type.GetCustomAttributes() to get the CategoryOrderAttribute instead of using TypeDescriptor.GetAttributes(). This is inconsistent with the way these types of attributes are retreived for the rest of property grid and prevents adding this metadata attribute for classes that lack it.

In Xceed.Wpf.Toolkit\PropertyGrid\Implementation\ObjectContainerHelper.cs around line 109 I changed the following code:

```
CategoryOrderAttribute[] orderAttributes = ( selectedObject != null )
? ( CategoryOrderAttribute[] )selectedObject.GetType().GetCustomAttributes( typeof( CategoryOrderAttribute ), true )
: new CategoryOrderAttribute[ 0 ];

```
to
```
CategoryOrderAttribute[] orderAttributes = (selectedObject != null)
? TypeDescriptor.GetAttributes(selectedObject.GetType()).OfType<CategoryOrderAttribute>().ToArray()
: new CategoryOrderAttribute[0];
```
Comments: ** Comment from web user: BoucherS **

Hi,
According to MSDN, when using TypeDescriptor.GetAttributes :

For attributes with AttributeUsageAttribute.AllowMultiple set to true, the attribute collection removes duplicate instances.

This means that using TypeDescriptor.GetAttributes instead of Type.GetCustomAttributes() will remove dupplicates of attributes. In the following example, only the first attribute will be considered, while they should all be considered.

```
[CategoryOrder( "Information", 1 )]
[CategoryOrder( "Hobbies", 2 )]
[CategoryOrder( "Connections", 3 )]
public class PersonOrdered : PersonBase { }
```
So the current code is kept.


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>