Академический Документы
Профессиональный Документы
Культура Документы
// A C# class type.
public class Calc
{
public int Add(int x, int y)
{ return x + y; }
}
2/1/2018 C# and .Net 33
CTS Class Characteristics
Class Characteristic Meaning in Life
// A C# interface type.
public interface IDraw
{
void Draw();
}
2/1/2018 C# and .Net 36
CTS Enumeration Types
Enumerations are programming construct that allows
us to group name/value pairs
// A C# enumeration type.
public enum CharacterType
{
Wizard = 100,
Fighter = 200,
Thief = 300
}
Mscorree.dll Microsoft
Common Object Runtime
Execution Engine.
41
2/1/2018 C# and .Net
Workflow of Common Language Runtime
• Runtime can be understood as a collection of external
services that are required to execute a given compiled unit of
code
• CLR is physically represented by a library named mscoree.dll
• When an assembly is referenced for use, mscoree.dll is loaded
automatically, which in turn loads the required assembly into
memory.
• The runtime engine is responsible for a number of tasks:
– It is the entity in charge of resolving the location of an assembly
– Finding the requested type within the binary by reading the contained
metadata.
• The CLR then lays out the type in memory, compiles the
associated CIL into platform specific instructions, performs
any necessary security checks, and then executes the code
42
2/1/2018 C# and .Net
.NET namespaces
• Namespace is a grouping of related types
contained in an assembly
• Namespaces can be used to organize code in
any way the programmer desires.
• A single assembly can contain any namespaces,
each of which can contain any number of types
– Mscorlib.dll
• Namespaces avoid naming conflicts between
identifiers.
43
2/1/2018 C# and .Net
Accessing namespace programmatically
•Using Keyword
// Explicitly list the namespaces used by this file.
using System;
using System.Drawing;
class MyApp
{ •Using fully qualified name
public void DisplayLogo() // Not listing System.Drawing namespace!
{ using System;
// Create a 20_20 pixel bitmap. class MyApp
{
Bitmap companyLogo = new Bitmap(20, 20);
public void DisplayLogo()
} {
} // Using fully qualified name.
System.Drawing.Bitmap companyLogo =
new System.Drawing.Bitmap(20, 20);..
}
}
44
2/1/2018 C# and .Net
.NET Namespace .NET Namespace Meaning in Life
46
2/1/2018 C# and .Net
.Net aware compiler Produces CIL instructions
47
2/1/2018 C# and .Net
48
2/1/2018 C# and .Net
49
2/1/2018 C# and .Net
The Role of .NET Type Metadata
• .NET assembly contains full, complete, and
accurate metadata, which describes each and
every type (class, structure, enumeration, and
so forth) defined in the binary, as well as the
members of each type (properties, methods,
events, and so on).
50
2/1/2018 C# and .Net
51
2/1/2018 C# and .Net
The Role of the Assembly Manifest
• the manifest documents all external
assemblies required by the current assembly
to function correctly, the assembly’s version
number, copyright information, and so forth.
• Like type metadata, it is always the job of the
compiler to generate the assembly’s manifest
52
2/1/2018 C# and .Net
53
2/1/2018 C# and .Net
54
2/1/2018 C# and .Net
55
2/1/2018 C# and .Net
Understanding the Common
Language Specification
• The Common Language Specification (CLS) is a set of
rules that describe in vivid detail the minimal and
complete set of features a given .NET-aware compiler
must support to produce code that can be hosted by
the CLR, while at the same time be accessed in a
uniform manner by all languages that target the .NET
platform
• The crème de la crème of the CLS is the mighty Rule 1:
• Rule 1: CLS rules apply only to those parts of a type
that are exposed outside the defining assembly.
56
2/1/2018 C# and .Net
57
2/1/2018 C# and .Net
Using ildasm.exe
• The Intermediate Language Disassembler utility (ildasm.exe) allows
you to load up any .NET assembly and investigate its contents,
including the associated manifest, CIL code, and type metadata.
• By default, ildasm.exe should be installed C:\Program
Files\Microsoft Visual Studio 8\SDK\v2.0\Bin
• File Open menu command and navigate to an assembly you wish
to explore
• ildasm.exe presents the structure of an assembly using a familiar
tree-view format
• Viewing CIL Code
• Viewing Type Metadata: to view the type metadata for the
currently loaded assembly, press Ctrl+M
• Viewing Assembly Metadata: To viewing the contents of the
assembly’s manifest, simply double-click the MANIFEST icon
58
2/1/2018 C# and .Net
The Platform-Independent Nature of .NET
59
2/1/2018 C# and .Net
Partitions of Meaning in Life
ECMA-335
60
2/1/2018 C# and .Net
Questions
1. What are the building blocks of .NET framework? Explain their
relationship with a neat block diagram. Explain the CTS, in detail.
2. Explain the CLR. Illustrate the workflow that takes place between the
source code, given .NET compiler and the .NET execution engine. What is
the role of .NET type Metadata? Give an example