Net Components And Types Bassem Elkarablieh Outline n
. Net Components And Types Bassem Elkarablieh
Outline n n n Modules Assemblies Object Model Types Runtime Type Information Programming with Types
. net Code Journey
CLR Architecture
Modules n n CLR programs reside into Modules contain: n n Code(IL code) Meta. Data ( module description) Resources (any external resource) Modules are not deployable components
Assemblies n n Modules are the physical construct of the program that resides in file system Assembly is a logical construct that interfaces with the CLR to access modules Assemblies are references by a logical name The CLR have a mechanism to identify assemblies
Assemblies continued n Assemblies are deployable modules n n n Each assembly has a manifest Assemblies might have multiple modules Only one manifest exists Manifests describe the modules in the assembly Assembly can be: n n Executable application Library
Assemblies
Compiling process n n csc /t: module Speaker 1. cs csc /t: module Speaker 2. cs csc /t: library /addmodule: Speaker 1. netmodule /addmodule: Speaker 2. netmodule Speakers. cs csc /t: exe /r: Speakers. dll Executive. cs
Manifests n Manifests contain: n n Filenames of the internal modules Type declaration of internal modules Name of the assembly Meta. Data Contain n n List of all external dependencies Type declarations of the assembly
Assembly names n Assembly names are four parts: n n n Logical friendly name Version number Culture Public Key Token Friendly names: simple name to reference the assembly Culture: “en-us”, ”ar-lb” Satellite
Versioning n Version number have the following structure: n Major. Minor. Build. Revision Number Actual Value 1 1. 0. 0. 0 1. 2. * 1. 2. d. s 1. 2. 3. * 1. 2. 3. s nothing 0. 0
Public Keys n n Public keys resolves name confusions of assemblies Public keys signs the module with the developer identity Private keys can be used to digitally sign the assembly Public key file can be generated using the sn. exe tool
Loading assemblies n n If assembly is partially specified it can be loaded by friendly name If assembly is fully specified , then the name should be resolved before the assembly is loaded
Loading Assemblies
. net Types n n Every class declared in. net is a type Types can include: n n Fields Methods Properties Events
CLR Type System
C++ Object Model
. net Runtime Object Model
Runtime type information object
How to call a method n n If the method is a member of the type , then 3 pointer references are used If the method is a base-member then more references are used depending on the length of the hierarchy
Type Casting n n n One of the main properties of. net is type safety. Disadvantage of type checking is performance. Three types of castings are possible: n n n Upcast Downcast Sidecast
Type Casting n n Casting is the process of a linear search and match of the handles in the interface table and the Class hierarchy. To support casting two opcodes are used( invisible from user) n n n Isinsit (is keyword) Castclass(as Keyword) Both opcode take the object and the desired type metadata pointer as arguments.
Type checking n n The System. Type class is a façade to the internal Type structure. Provides methods to check type compatibility n n Is. Compatible, Issubclassof To get the type handle of any object use the inherited object. get. Type()
Programming With Types
System. Reflection n n This namespace provide the Assembly object used in loading assemblies The assembly object allows the accessing of the typemetadata. Given the metadata we can get the type handle references. Given the type Handel we can get member info.
System. Type n n n Assembly Asm = Assembly. Loadfrom(“x. dll”); Type[] types = Asm. Get. Types(); Foreach(Type t in types) n n T. Get. Members() T. Get. Methods() T. Get. Fields() T. Get. Events()
Filtering Type selection n n Using bindingflags Binding. Flags f = static|Instance|public|nonpublic|Flatten Hirarchy T. Get. Members(f); We can also filter by name and the member type
End of Presentation
- Slides: 29