Description:
There are two classes, A and B, I A inherits class B, and then B is the parent class
I have set the TestAttribute properties in class A and class B respectively...
Then, take the characteristics of the object, and the code is as follows:
I found that the number of results is 1, and the attribute is the attribute set by A, not the attribute set by B, let alone merged, why is this???
[Help("BaseClass")] publicclass Base{} publicclass Derive : Base{} There are four possible combinations here:
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false ] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false ] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true ] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true ] The first case:
If we query the Derive class (we'll see later how to query a class's properties at runtime), we'll find that the Help feature doesn't exist because the inherited property is set to false.
Second case:
Same as in the first case, because inherited is also set to false.
The third situation:
To explain the third and fourth cases, let's first add some code to the derived class:
[Help("BaseClass")] publicclass Base{}[Help("DeriveClass")] publicclass Derive : Base{} Now let's query the Help feature, we can only get the properties of the derived class, because inherited is set to true, but AllowMultiple is set to false. Therefore, the Help feature of the base class is overridden by the help feature of the derived class.
The fourth situation:
Here we will find that the derived class has both the Help feature of the base class and its own Help feature, because AllowMultiple is set to true.
|