One of the major goals of .NET is language interoperability. If you wrap a native library, language interoperability is of special importance because the clients of the wrapper library are likely developers using C# or other .NET languages. As defined in Chapter 1, the Common Language Infrastructure (CLI) is the base specification of .NET. An important aspect of this specification is the Common Type System (CTS). Even though all .NET languages share the same type system, not all .NET languages support all features of that type system.
To provide a clear definition of language interoperability, the CLI contains the Common Language Specification (CLS). The CLS is a contract between developers writing .NET languages and developers writing language-interoperable class libraries. The CLS specifies what CTS features a .NET language should support at least. To ensure that a library can be used by all .NET languages that conform to the CLS, the set of CLS features is the upper limit for all parts of a class library that are visible outside of an assembly. These are all public types and all members of public types that have public, public protected, or protected visibility.
The CLSCompliantAttribute can be used to express that a type or type member is CLS-compliant. By default, types that are not marked with this attribute are considered to be non-CLS-compliant. By applying this attribute at the assembly level, you can specify that all types in the assembly should be considered CLS-compliant by default. The following code shows how to apply this attribute to assemblies and types:
using namespace System;
Was this article helpful?