CHAPTER 18 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES
Table 18-3. Various Attributes Used in Conjunction with the .class Directive
Attributes
Meaning in Life
public, private, nested assembly,
nested famandassem, nested family,
nested famorassem, nested public,
nested private
CIL defines various attributes that are used to specify the
visibility of a given type. As you can see, raw CIL offers
numerous possibilities other than those offered by C#. Refer to
ECMA 335 for details if you are interested.
abstract, sealed
These two attributes may be tacked onto a .class directive to
define an abstract class or sealed class, respectively.
auto, sequential, explicit
These attributes are used to instruct the CLR how to lay out
field data in memory. For class types, the default layout flag
(auto) is appropriate. Changing this default can be helpful if
you need to use P/Invoke to call into unmanaged C code.
extends, implements
These attributes allow you to define the base class of a type (via
extends) or implement an interface on a type (via implements).
Defining and Implementing Interfaces in CIL
As odd as it might seem, interface types are defined in CIL using the .class directive. However, when the
.class directive is adorned with the interface attribute, the type is realized as a CTS interface type.
Once an interface has been defined, it may be bound to a class or structure type using the CIL
implements attribute, like so:
.namespace MyNamespace
{
// An interface definition.
.class public interface IMyInterface {}
// A simple base class.
.class public MyBaseClass {}
// MyDerivedClass now implements IMyInterface,
// and extends MyBaseClass.
.class public MyDerivedClass
extends MyNamespace.MyBaseClass
implements MyNamespace.IMyInterface {}
}
Note The extends clause must precede the implements clause. As well, the implements clause can
incorporate a comma-separated list of interfaces.
666