Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/CategoryOrderAttribute fixes #1523

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ public string CategoryValue

#endregion

#region TypeId

public override object TypeId
=> CategoryValue;

#endregion TypeId

#endregion

#region constructor
Expand All @@ -73,4 +80,3 @@ public CategoryOrderAttribute( string categoryName, int order )
#endregion
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,20 @@ private PropertyItem CreatePropertyItem( PropertyDescriptor property, PropertyDe
return propertyItem;
}

private int GetCategoryOrder( object categoryValue )
private int GetCategoryOrder(object categoryValue)
{
Debug.Assert( SelectedObject != null );
Debug.Assert(SelectedObject != null);

if( categoryValue == null )
if (categoryValue == null)
return int.MaxValue;

int order = int.MaxValue;
object selectedObject = SelectedObject;
CategoryOrderAttribute[] orderAttributes = ( selectedObject != null )
? ( CategoryOrderAttribute[] )selectedObject.GetType().GetCustomAttributes( typeof( CategoryOrderAttribute ), true )
: new CategoryOrderAttribute[ 0 ];
object selectedObject = SelectedObject;

var orderAttribute = orderAttributes
.FirstOrDefault( ( a ) => object.Equals( a.CategoryValue, categoryValue ) );
var orderAttribute = TypeDescriptor.GetAttributes(selectedObject)
.OfType<CategoryOrderAttribute>()
.FirstOrDefault(a => Equals(a.CategoryValue, categoryValue));

if( orderAttribute != null )
{
order = orderAttribute.Order;
}

return order;
return orderAttribute?.Order ?? int.MaxValue;
}








}
}