C #: How to use the CategoryAttribute.Appearance property

I got a little familiar with the design-time attributes for components . There I found the CategoryAttribute attribute . This page says that

The CategoryAttribute class defines the following general categories:

And then lists a few general categories. One of them, for example, Appearance . I thought brilliant! Then I can use [Category.Appearance]instead [Category("Appearance")]! But apparently I could not? I tried to write this, but Intellisense did not pick it up, and he did not intend to. Am I missing something? Perhaps these were the wrong properties? If not, what are they for? If so, how to use them?

And yes, I have the right usingone to have access to CategoryAttributecause work [Category("Whatever")]. I'm just wondering how I use those specific general categories.

+3
source share
2 answers

As you can see on MSDN, this is only a getter property, not a setter.

public static CategoryAttribute Appearance { get; }

Actually, here is what the code looks like using Reflector:

 public static CategoryAttribute Appearance
    {
        get
        {
            if (appearance == null)
            {
                appearance = new CategoryAttribute("Appearance");
            }
            return appearance;
        }
    }

So it’s not so much.

The only thing I see for him is something like this:

            foreach (CategoryAttribute attrib in prop.GetCustomAttributes(typeof(CategoryAttribute), false))
            {
                bool result = attrib.Equals(CategoryAttribute.Appearance);
            }

Basically, when using reflection to view a class, you can easily check which category it belongs to without having to compare String. But you cannot use it as you unfortunately do.

+3
source

CategoryAttribute.Appearance. , , . , [ ( " " )].

+2

Source: https://habr.com/ru/post/1704272/


All Articles