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

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

Open
MarqueIV opened this issue Aug 19, 2019 · 2 comments

Comments

@MarqueIV
Copy link

MarqueIV commented Aug 19, 2019

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

@MarqueIV MarqueIV changed the title Update ObjectContainerHelper.GetCategoryOrder to use the TypeDescriptor to get programmatically-added attributes Update ObjectContainerHelper.GetCategoryOrder to use the TypeDescriptor to get attributes Aug 19, 2019
@MarqueIV
Copy link
Author

I figured out how to create a PR here, so I went ahead and created one. It's here... #1523

@XceedBoucherS
Copy link
Collaborator

Thank you.
This will be included in v3.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants