Metadata (CLI)

A CLI language compiler will generate the metadata and store this in the assembly containing the CIL.

A difference in use within the Common Language Runtime is that an assembly typically does not contain any CIL instructions.

Windows Communication Framework uses attributes to define service contracts, ASP.NET uses these to expose methods as web services, LINQ to SQL uses them to define the mapping of classes to the underlying relational schema, Visual Studio uses them to group together properties of an object, the class developer indicates the category for the object's class by applying the [Category] custom attribute.

The attribute can be prefixed with "@" if you don't want to risk ambiguity, so writing [@Custom] will not match CustomAttribute.

The valid targets are assembly, field, event, method, module, param, property, return and type.

The Framework SDK contains a sample called metainfo that will list the metadata tables in an assembly, however, this information is rarely of use to a developer.

Metadata in an assembly may be viewed using the ILDASM tool provided by the .NET Framework SDK.

Reflection in version 1.1 of the .NET framework can be used to inspect the descriptions of classes and their members, and invoke methods.

The Microsoft .NET Framework ships a CLR metadata manipulation library that is implemented in native code.

Third-party tools to retrieve and manipulate metadata include PostSharp and Mono Cecil can also be used.