Professional Documents
Culture Documents
programming language designers and class library authors. On the one hand
the language designers such as C#, VB, C++, Cobol, Eiffel, FORTRAN, etc
agree to extend their languages to support, through some means, the ability
to access functionality exposed with features from the CLS. On the other
hand library designers (such as the .NET Framework, WinFX, 3 rd party
controls, etc) agree to expose all their functionality in such a way that it can
be used with just those features from the CLS.
The CLS is basically just a subset of the entire set of features supported by
the CLR. The CLS includes things such as calling virtual methods,
overloading methods and does not include things such as unsigned types.
The first thing you will notice is that the CLS is weighted very heavily in favor
of the library designers. Nearly every meaningful feature of the CLR is
exposed in the CLS. We initially started with the idea that we’d just use the
subset of all programming languages but quickly discovered that would leave
only calling static methods (if that). So we opted, wisely, to include nearly
everything a library designer might need. This is actually a big win for
language vendors because at least they have a clearly spelled out list of
things they need to support. It is not something you find out by testing
1,000s of libraries in the wild.
Why should you care? Well, if you are just building end applications or
libraries that will only be used by a single language don’t worry about the
CLS. Use all the features your language of choice offers you. If you are
building a library that you hope to be used by a wide range of developers you
might find it useful to conform to the CLS such that you have an open ended
market. After all, who knows when that next big language will catch on and
be as big as VB, C# or C++? Ruby, Python, etc all have a chance. If you
conform to the CLS your library will be useable by that language. Lastly, if
you are a language designer, it is clearly in your interest to take advantage
of the rich set of functionality exposed in the .NET Framework, WinFX and 3 rd
party libraries. To do so, all you need to do is support all the CLS constructs.
Source Code => Compiler => Assembley =>Class Loader =>Jit Compiler
=>Manged Native Code=>Execution.
To fully interact with other objects regardless of the language they were
implemented in, objects must expose to callers only those features that are
common to all the languages they must interoperate with. For this reason,
the Common Language Specification (CLS), which is a set of basic language
features needed by many applications, has been defined. The CLS rules
define a subset of the common type system; that is, all the rules that apply
to the common type system apply to the CLS, except where stricter rules are
defined in the CLS. The CLS helps enhance and ensure language
interoperability by defining a set of features that developers can rely on to be
available in a wide variety of languages. The CLS also establishes
requirements for CLS compliance; these help you determine whether your
managed code conforms to the CLS and to what extent a given tool supports
the development of managed code that uses CLS features.
If your component uses only CLS features in the API that it exposes to other
code (including derived classes), the component is guaranteed to be
accessible from any programming language that supports the CLS.
Components that adhere to the CLS rules and use only the features included
in the CLS are said to be CLS-compliant components.
Most of the members defined by types in the .NET Framework class library
are CLS-compliant. However, some types in the class library have one or
more members that are not CLS-compliant. These members enable support
for language features that are not in the CLS. The types and members that
are not CLS-compliant are identified as such in the reference documentation,
and in all cases a CLS-compliant alternative is available. For more
information about the types in the .NET Framework class library, see the
.NET Framework Reference.
The CLS was designed to be large enough to include the language constructs
that are commonly needed by developers, yet small enough that most
languages are able to support it. In addition, any language construct that
makes it impossible to rapidly verify the type safety of code was excluded
from the CLS so that all CLS-compliant languages can produce verifiable code
if they choose to do so. For more information about verification of type
safety, see JIT Compilation.
The following table summarizes the features that are in the CLS and indicates
whether the feature applies to both developers and compilers (All) or only
compilers. It is intended to be informative, but not comprehensive. For
details, see the specification for the Common Language Infrastructure,
Partition I, which is located in the Tool Developers Guide directory installed
with the Microsoft .NET Framework SDK.
The common type system defines how types are declared, used, and
managed in the runtime, and is also an important part of the runtime's
support for cross-language integration. The common type system performs
the following functions:
Establishes a framework that helps enable cross-language integration,
type safety, and high performance code execution.
Provides an object-oriented model that supports the complete
implementation of many programming languages.
Defines rules that languages must follow, which helps ensure that
objects written in different languages can interact with each other.
These methods are compiled the first time they are called, and then they are
stored in cache. When the same methods are called again, the compiled code
from cache is used for execution.
When compiling the source code to managed code, the compiler translates
the source into Microsoft intermediate language (MSIL). This is a CPU-
independent set of instructions that can efficiently be converted to native
code. Microsoft intermediate language (MSIL) is a translation used as the
output of a number of compilers. It is the input to a just-in-time (JIT)
compiler. The Common Language Runtime includes a JIT compiler for the
conversion of MSIL to native code.