We have a custom attribute
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class CustomDesignerAttribute: Attribute
the
I think it is possible in the following way:
In your CustomDesignerAttribute overwrite TypeId:
public override object TypeId
{
get
{
return Key.GetHashCode();
}
}
The base implementation of TypeId just uses the attribute type, so no parameters would be involved.
Then u can use
TypeDescriptor.GetAttributes(typeof(ChildClass)).OfType
TypeDescriptor (in contrast to GetType().GetCustomAttributes) returns only one attribute based on the same TypeId. I tested it and it is the most derived attribute matching the TypeId that is returned.
So if your TypeId represents the key of your attribute then you can overwrite it on derived classes - when using TypeDescriptor to get the attribute! Note that still multiple attributes are possible as long as they differ in their key.
Note: TypeDescriptor also finds dynamically added attributes (added at runtime)
You could add a public bool Remove { get; set; } to your CustomDesignerAttribute. You can set it to true in your derived class while setting the other parameters identical to the base class attribute you want to remove. Then add another attribute with same key but your desired value to your derived class. When getting the attributes you have to evaluate the Remove property in a smart manner. Either using TypeDescriptor as in 1) with TypeId e.g. returning Key.HashCode() + Value.GetHashCode() or using GetType().GetCustomAttributes, in both ways you have to loop through the list of attributes and filter. You have to be aware in what order these lists are, if most derived types first or the other way around.