
Hello,
When you have multiple objects their common properties (where their name and type are the same) are merged. In this case you could have two different sort orders for the "same" property. Assuming that this is not a problem in you case and that you used our Sort w/ Custom Attribute QuickStart, you could update the SortOrderComparer.GetSortOrder method to something like the following:
/// <summary>
/// Gets the sort order of the specified property.
/// </summary>
/// <param name="obj">The property whose sort order should be returned.</param>
/// <returns>The sort order of the specified property.</returns>
private static int GetSortOrder(object obj) {
CustomSortCategoryDataAccessor categoryAccessor = obj as CustomSortCategoryDataAccessor;
if (categoryAccessor != null)
return categoryAccessor.SortPriority;
PropertyDescriptorDataAccessorBase propertyAccessor = obj as PropertyDescriptorDataAccessorBase;
if (propertyAccessor == null) {
// Determine if this is a merged property and if so then get the sort order from the first property
MergedPropertyDataAccessor mergedPropertyAccessor = obj as MergedPropertyDataAccessor;
if (mergedPropertyAccessor != null && mergedPropertyAccessor.PropertyDataAccessors.Count != 0)
propertyAccessor = mergedPropertyAccessor.PropertyDataAccessors[0] as PropertyDescriptorDataAccessorBase;
}
if (propertyAccessor != null && propertyAccessor.PropertyDescriptor != null) {
SortOrderAttribute sortOrder = propertyAccessor.PropertyDescriptor.Attributes[typeof(SortOrderAttribute)] as SortOrderAttribute;
if (sortOrder != null)
return sortOrder.Priority;
}
return 0;
}
In the code above, we use the SortOrderAttribute of the first merged property. You may want to use different logic to resolve which SortOrderAttribute to use.
This will also be included in the sample for the next maintenance release.