attributes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

simple question,
are attributes inherited?
eg if base class is marked serializable are classes that inherit from it
also serializable?
 
guy said:
simple question,
are attributes inherited?
eg if base class is marked serializable are classes that inherit from
it also serializable?

Attributes are confusing because some are real attributes (like
[Serializable]) others are custom attributes (that is, they add the
..custom metadata).

In your specific case [Serializable] is not inheritable because the base
class does not know the fields of the child class and so it does not
know whether those are serializable, or whether the client wants them to
be serializable. Only the class itself can know if its fields can be or
should be serialized.

For custom attributes only: each custom attribute is derived from
Attribute and has to have the [AttributeUsage] attribute. This attribute
has a property, Inherited, which indicates if the child class will
inherit the attribute. So if you look up the documentation for a custom
attribute in MSDN you'll see whether it is inheritable or not.

Richard
 
Back
Top