Common Language Specification

from Wikipedia, the free encyclopedia

The Common Language Specification ( CLS ) is part of the Common Language Infrastructure standard, which enables the development of programming language- neutral program components. The CLS guarantees that every program or every part of the program (e.g. a single class) that has been developed in accordance with the CLS can be used in full in any other CLS-compatible programming language.

Common Language Specification concept

As part of the programming language- neutral platform of a Common Language Infrastructure implementation (e.g. .NET from Microsoft ), it is necessary to regulate the interaction between different programming languages. Since not every programming language offers the same range of functions, cross-language programming is not possible automatically. For this reason, the CLS specifies a subset of the CLI standard that every CLS-compatible programming language must at least understand in order to produce language neutrality. The rules of the CLS always only apply to public (public or protected) interfaces. In terms of internal implementation, there are no restrictions from the CLS.

Implementation of the Common Language Specification

Most programming languages ​​from the .NET environment allow developers to choose whether they want to develop their programs or program components in a CLS-compatible manner. For this purpose, the metadata attribute [ClsCompliant (true)] is usually used, which instructs the compiler (e.g. from C # or VB.NET ) to check during compilation whether the CLS was complied with. If this is not the case, a compiler error is generated.

All parts of the .NET class libraries are CLS-compatible.

Examples

The following list contains some examples of items that are not CLS compatible. These can be part of the implementation, but must not be used as part of the public interfaces.

  • Unsigned data types such as B. uint, ulong.
  • Elements (classes, methods, fields, etc.) that only differ in their name being capitalized.
  • Pointer and all other related constructs and language elements (referred to as “unsafe” in the context of .NET).
  • Global static methods
  • Interfaces with static methods or fields
  • Classes that do not inherit from CLS-compliant classes
  • Variable size arrays or arrays that do not start at element 0
  • Overloading fields and events

Web links