The .override directive specifies that a virtual method shall be implemented (overridden), in this type, by a virtual method with a different name, but with the same signature. This directive can be used to provide an implementation for a virtual method inherited from a base class, or a virtual method specified in an interface implemented by this type. The .override directive specifies a Method Implementation (MethodImpl) in the metadata (§II.15.1.4).
ClassMember ::= | Clause |
---|---|
.override TypeSpec '::' MethodName with CallConv Type TypeSpec '::' MethodName '(' Parameters ')' |
|
.override method CallConv Type TypeSpec '::' MethodName GenArity '(' Parameters ')' with method CallConv Type TypeSpec '::' MethodName GenArity '(' Parameters ')' |
|
| … | §II.10.2 |
GenArity ::= |
---|
[ '<' '[' Int32 ']' '>' ] |
Int32 is the number of generic parameters. The first TypeSpec::MethodName pair specifies the virtual method that is being overridden, and shall be either an inherited virtual method or a virtual method on an interface that the current type implements. The remaining information specifies the virtual method that provides the implementation.
While the syntax specified here (as well as the actual metadata format (§II.22.27)) allows any virtual method to be used to provide an implementation, a conforming program shall provide a virtual method actually implemented directly on the type containing the .override directive.
[Rationale: The metadata is designed to be more expressive than can be expected of all implementations of the VES. end rationale]
[Example: The following shows a typical use of the .override directive. A method implementation is provided for a method declared in an interface (see §II.12).
.class interface I
{ .method public virtual abstract void M() cil managed {}
}
.class C implements I
{ .method virtual public void M2()
{ // body of M2
}
.override I::M with instance void C::M2()
}
The .override directive specifies that the C::M2
body shall provide the implementation of be used to implement I::M
on objects of class C
. end example]