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.
Bfree source
share