Introduction to ASP.NET - The Common Language Infrastructure (CLI)
(Page 3 of 10 )
The CLI is a subset of the .NET Framework that has been submitted for standardization through the ECMA standards body. The CLI includes the functionality of the Common Language Runtime, as well as specifications for the Common Type System, type safety rules, Metadata, and Intermediate Language. It also includes a subset of the Framework Class Library that includes a Base Class Library (for built-in types and basic runtime functionality), a Network Library (for simple networking services and access to network ports), a Reflection Library (for examining types and retrieving information about types at runtime), an XML Library (for parsing XML), and Floating Point and Extended Array Libraries.
Microsoft has also committed to providing what they refer to as a “sharedsource” implementation of the CLI, which will be available for both the FreeBSD and Windows operating systems. You can find out more about the shared-source CLI implementation at http://msdn.microsoft.com/library/en-us/dndotnet/html/mssharsourcecli2.asp.
There is also a group working on an open source implementation of the CLI, based on the ECMA specifications, called Mono. You can find out more about Mono at http://www.go-mono.org/.
Information on the ECMA standardization process, including documentation of the proposed standards, is available at http://msdn.microsoft.com/net/ecma/.
The Common Language Specification (CLS) The CLS is a subset of the types supported by the CLR, as well as a set of rules that language and compiler designers must follow. The purpose of the CLS is to provide robust interoperability between .NET languages, including the ability to inherit classes written in one .NET language in any other .NET language and cross-language debugging.
The rules defined by the CLS apply only to publicly exposed features of a class. For example, the internal implementation of a class can use non-CLS–compliant types (such as the unsigned integer types), but as long as only CLS-compliant members are exposed publicly, the class can still take full advantage of the interoperability features enabled by the CLS.
Classes While not a term specific to the .NET platform, the term class may be new to many ASP developers. A class is essentially the blueprint for an object. It contains the definition for how a particular object will be instantiated at runtime, such as the properties and methods that will be exposed publicly by the object and any internal storage structures.
Developers work with classes by creating instances of the class at runtime using the new keyword, as shown here:
// Instantiate the .NET StreamReader class in C# System.IO.StreamReader sr;
sr = new System.IO.StreamReader("C:\\Test.txt");
string Line;
while(sr.Peek() != -1)
{
Line = sr.ReadLine();
Response.Write(Server.HtmlEncode(Line) + " <br/>");
}
We preface the name of the class, StreamReader, with its namespace name, System.IO, to prevent naming collisions with other classes in different assemblies that might have the same name and to ensure that we get the StreamReader class we expect. We’ll discuss namespaces and assemblies later in this section.
In C#, the lowercase new keyword is used to instantiate classes. In Visual Basic .NET, the New keyword is uppercase, but since the Visual Basic language is not case-sensitive, this is a standard practice, rather than a requirement enforced by the compiler. C#, on the other hand, is case-sensitive, so keep this in mind when switching between C# and VB.NET.
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Namespaces >>
More ASP.NET Articles
More By O'Reilly Media