What doesn't get inherited in .Net?
I guess I was surprised to learn that Implements
or <Serializable()>
do not get inherited fr开发者_开发技巧om class to class which means that it must be redefined each I want to recreated those behaviors. I was wondering what else isn't inhertible in .Net? Thanks
These are 2 different items: interface and attribute inheritance.
The Inherits
portion refers to how interfaces behave across class hierarchies. Interfaces are indeed inherited. If a given base class implements IFactory
then all of it's derived types will. There are certain language oddities on how a derived class can re-implement the interface or specific methods. However at a .Net level once a base class implements an interface all derived classes will as well.
Whether or not an attribute is inherited depends on the value of AttributeUsage.Inherited
on the AttributeUsage
for the given attribute. In the case of Serializable
it's marked as Inherits=false
and won't be inherited. Every attribute must pick their own behavior here.
The long answer would take too long, but the short answer is any class using the sealed
(c#) or NotInheritable
(VB.NET) modifier.
http://msdn.microsoft.com/en-us/library/88c54tsw%28v=vs.71%29.aspx
精彩评论