A type header consists of
-
any number of type attributes,
-
optional generic parameters
-
a name (an Id),
-
a base type (or base class type), which defaults to
[mscorlib]System.Object
, and -
an optional list of interfaces whose contract this type and all its descendent types shall satisfy.
ClassHeader ::= |
---|
ClassAttr* Id [ '<' GenPars '>' ] [ extends TypeSpec [ implements TypeSpec ] [ ',' TypeSpec ]* ] |
The optional generic parameters are used when defining a generic type (§II.10.1.7).
The extends keyword specifies the base type of a type. A type shall extend from exactly one other type. If no type is specified, ilasm will add an extends clause to make the type inherit from System.Object
.
The implements keyword specifies the interfaces of a type. By listing an interface here, a type declares that all of its concrete implementations will support the contract of that interface, including providing implementations of any virtual methods the interface declares. See also §II.11 and §II.12.
The left-to-right order of the TypeSpec after the implements keyword is preserved as a top-to-bottom ordering in the InterfaceImpl table (§22.23). This is required to support variance resolution in interface dispatch (§12.2).
[Example: This code declares the class CounterTextBox
, which extends the class System.Windows.Forms.TextBox
in the assembly System.Windows.Forms
, and implements the interface CountDisplay
in the module Counter
of the current assembly. The attributes private, auto and autochar are described in the following subclauses.
.class private auto autochar CounterTextBox
extends [System.Windows.Forms]System.Windows.Forms.TextBox
implements [.module Counter]CountDisplay
{ // body of the class }
end example]
A type can have any number of custom attributes attached. Custom attributes are attached as described in §II.21. The other (predefined) attributes of a type can be grouped into attributes that specify visibility, type layout information, type semantics information, inheritance rules, interoperation information, and information on special handling. The following subclauses provide additional information on each group of predefined attributes.
ClassAttr ::= | Description | Clause |
---|---|---|
abstract |
Type is abstract. | §II.10.1.4 |
| ansi |
Marshal strings to platform as ANSI. | §II.10.1.5 |
| auto |
Layout of fields is provided automatically. | §II.10.1.2 |
| autochar |
Marshal strings to platform as ANSI or Unicode (platform-specific). | §II.10.1.5 |
| beforefieldinit |
Need not initialize the type before a static method is called. | §II.10.1.6 |
| explicit |
Layout of fields is provided explicitly. | §II.10.1.2 |
| interface |
Declares an interface. | §II.10.1.3 |
| nested assembly |
Assembly accessibility for nested type. | §II.10.1.1 |
| nested famandassem |
Family and assembly accessibility for nested type. | §II.10.1.1 |
| nested family |
Family accessibility for nested type. | §II.10.1.1 |
| nested famorassem |
Family or assembly accessibility for nested type. | §II.10.1.1 |
| nested private |
Private accessibility for nested type. | §II.10.1.1 |
| nested public |
Public accessibility for nested type. | §II.10.1.1 |
| private |
Private visibility of top-level type. | §II.10.1.1 |
| public |
Public visibility of top-level type. | §II.10.1.1 |
| rtspecialname |
Special treatment by runtime. | §II.10.1.6 |
| sealed |
The type cannot be derived from. | §II.10.1.4 |
| sequential |
Layout of fields is sequential. | §II.10.1.2 |
| serializable |
Reserved (to indicate this type can be serialized). | §II.10.1.6 |
| specialname |
Might get special treatment by tools. | §II.10.1.6 |
| unicode |
Marshal strings to platform as Unicode. | §II.10.1.5 |