Skip to content

Update ObjectContainerHelper.GetCategoryOrder to use the TypeDescriptor to get attributes #1522

Open
@MarqueIV

Description

@MarqueIV

The existing code which simply called GetCustomAttributes doesn't take into consideration those attributes added via a TypeDescriptor. As such, you should use the TypeDescriptor.AddAttributes which gets both those defined on the class at compile time, plus those added at runtime.

Note: In a semi-related issue, here, the CategoryOrderAttribute needs to add the following override to work correctly.

public override object TypeId => CategoryValue;

I don't have the ability to create PRs or I'd submit this myself, but here's the needed function.

private int GetCategoryOrder(object categoryValue) {

  Debug.Assert(SelectedObject != null);

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

  object selectedObject = SelectedObject;

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

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

HTH!

Mark

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions