The philosophy of .

NET

Ramesh shettigar Lecturer, Department of CS & E, NMAM Institute of Technology, Nitte

Life as a C/Win32 API Programmer
       

Windows family of OS C + Win API Very terse language. Manual Memory Management. Ugly pointer Arithmetic. Ugly Syntactical constructs. Structured language => lacks benefits of OOP. 1000‟s of global funs. & data types by raw API caused buggy apps.

Life as a C++/MFC Programmer
   

C++ = OO Layer on top of C. Benefits of Pillars of OOP (EIP) Disadvantages of C still carry. MFC – Wrap a sane subset of raw Win32 API behind a no. of Classes, magic macros & numerous code wizards. Difficult and error-prone programming.

Life as a VB 6.0 Programmer

Ability to build complex UI, code libraries, & DAL with less effort. Also hides the complexity of raw Win32 API by no. of integrated code wizards, IDT, Classes & VB Centric functions. Not OOL, its “Object aware” language. Eg :- No Classical inheritance (is-a rels) b/n types, no support for parameterized class construction. No support for multithreaded apps.

 

Java Language : Platform independence. . Java front-to-back during development. of predefined packages having various class & interface definitions. Problem to merge existing code with new one. For graphics intensive product the execution speed will leave something to be desired. Java Platform : Large no. So little hope of language independence. no ugly syntax of C++. Limited ability to access non-Java API’s.Life as a Java/J2EE Programmer        Completely OOL and syntactic roots in C++.

ATL – Active Template Lib.g.independent manner. Binary COM : access in a language . No support for classical inheritance. you end up with a block of reusable binary code. Fragile registration entries & numerous deployment related issues. Simplifying the task.:.C++ COM Classes can be used by VB. Extremely complex under development. Benefit: Location-transparent nature. E.Life as a COM Programmer         If you build your classes in accordance with the rules of COM. (DLL hell). .

ASP. Highly confused mismatch of technologies. VBS. It requires numerous tech & langs. . HTML. “int” in JS != “int” in C. COM(+)… many of them unrelated from syntactic point.      Each has its own type system. It is “Integer” in VB. JS.Life as a Windows DNA Programmer  Web app development using Classic DNA – Distributed iNternet Architecture is complex. XML.

No more COM Plumbing.NET Solution – Features of . .     A truly simplified deployment model.NET-aware languages.NET    Full interoperability with existing Win32 Code Complete and total language integration. A base class library that provides shelter from the complexities of raw API calls. (side-by-side execution). A common runtime engine shared by all .The . Consistent Object Model.

NET programming languages can agree on. Set of rules that define a subset of common types & programming constructs that all .NET metadata format. CTS: Common Type System. Locate. CLS  CLR: Common Language Runtime.NET types on your behalf. representation in the . CLS: Common Language Specification. Lang integration. programming constructs. CTS.   . their interaction. Automatic Memory Mgmt. Load & Manage .Building blocks: CLR. Describes all possible DT‟s. ensuring type safety.

The Role of the .NET BCL’s The Base Class Libraries Data Access Threading GUI File IO Security Debugging XML/SOAP (et al.) The Common Language Runtime Common Type System Common Language Specification .

   .Features offered by C# Languages    No need for direct pointer manipulation Automatic Memory Management (No „delete‟) Formal syntactic constructs for enumerations. (True object references passed between boundaries via value or reference) Full support for aspect-based programming techniques via attributes. structures & class properties. Operator Overloading for a custom type (Sure to return * this is not programmers job) Full support for interface-based programming techniques.

htm) Fortran.com) Smalltalk.dyadic.NET (http://www.eiffel.NET (http://www.com) Perl.ch http://www/cs.ch) .oberon.microsoft.ethz.NET (http://lahey.inf.com/projects/ilx/fsharp.activestate.adtools.NET (http://www.com) COBOL.NET & Python.ethz..com) F# (http://research. APL.NET (http://www.com) .NET (S#) (http://smallscript.NET (http://www.com) Eiffel.NET Aware Programming Languages         Oberon.

Platform-specific instructions until absolutely necessary. No internal similarities with COM.An Overview of .NET & COM dll. C# Source Code  C# Compiler  MSIL & Metadata Assembly Perl to Perl .NET Binaries        *. .exe.NET Compiler  Assembly contains CIL Code (|||r java byte code).NET SC (dll or exe)  Perl to Perl .dll or *. Not registered into the system registry. No runtime communication between . Not described using IDL. No platform-specific instructions like COM but platformagnostic “Intermediate Language” (IL).

    Manifest contains info about the current version of the assembly. Assemblies themselves are described using Metadata called as Manifest.NET aware compiler. culture information. Metadata is always present & is automatically generated by a given . Eg: Car Class. list of externally referenced assemblies that are used for proper execn. . Metadata |||r to classic COM type information.Metadata & Manifest  Metadata : Describes in vivid detail the characteristics of every “type” within the binary.

NET dll.NET assembly & the underlying dll or exe binary. composed of a single dll or exe. More flexible deployment & Versioning.  Multifile assemblies – numerous . binary & assembly are same.e. Assembly i. Contain CIL. Primary module contain assembly manifest + CIL + MD Related modules contain module level manifest + CIL + MD.. termed as module. metadata & manifest in a single package.   .NET assemblies.Single File & Multifile Assemblies  One-to-one correspondence between a .   For .

Common Intermediate Language (CIL)  Role: Language that sits above any particular platformspecific instruction set. CIL: Not a platform specific instructions.NET aware language associated. develop in any language & run it on any platform. Single code base running on numerous OS.    . Compiler emits CIL instructions regardless of the . Benefits: Language integration.

as well as members (properties. events…) of each type. complete & accurate metadata. methods.NET Assembly = CIL + full. struct…) defined in the binary.exe compiler binary format (type lib) ---used by COM aware language-- manipulate combined types.Metadata  Role: COM – IDL is a meta language used to describe the types contained within a given COM Server. .  IDL ------midl.   . Metadata : Describes each & every type (class. enum.

Metadata (contd..NET Remoting.)  Manifest : is a metadata describing the assembly itself. reflection service & Object serialization.  .   Uses: various object browsing utilities. by C# complier. debugging tools.. Benefits: Backbone of . required by the executing assembly to operate correctly. Also describes each externally referenced assembly i.e. IntelliSense.

Features: documents the list of external assemblies that have been referenced by the . . It is the job of the compiler to generate the assembly‟s manifest.assembly extern)    Also lists the various characteristics of the binary itself (. . .exe. (.Manifest  It describes the code library itself.module directives).ver.assembly.

the Jitter will be equipped to run within a low-memory env. Single code can be efficiently JIT compiled & executed on machines with different architectures.   Eg: For a handheld device.   . .NET env leverages a JIT compiler for each CPU targeting CLR.Compiling CIL to Platform-Specific Instructions  JIT Compiler or Jitter compiles the CIL into meaningful CPU instructions. Also Cache the results in memory suitable to OS.

Common Type System (CTS)  An assembly may contain any number of distinct “types”.NET aware language. of syntactic constructs that may or may not be supported by a given . interface. For a general assembly CLS conformance is a must. structure. It defines no.   CTS is a common specification that describes how a given type must be defined in order to be hosted by the CLR.   .NET type: An entity from the set {Class. . enumeration. delegate }.

of members. CTS may only derive from a single base class (No multiple inheritance for class types) CTS Class Characteristics. CTS allows a given class to support virtual & abstract members that define a polymorphic interface for derived classes.CTS Class Types  A class may be composed of any no.    .

Is the class abstract or concrete ? Abstract classes cannot be directly created. Is the class “Sealed” or not ? Sealed classes cannot function as a base class to other types. 2. Concrete classes can be created directly. 3. CTS allows a class to implement any no. of interfaces.CTS Class Characteristics 1. Does the class implement any interface ? I/F : collection of abstract members that provide a contract between the object & object user. but are inherited to define common behaviors for derived types. .

private.) 4. protected. . public.. Defines if the class may be used by external assemblies. internal.CTS Class Characteristics (contd. or within that assembly. What is the “visibility” of this class ? Each class must be configured with a visibility attribute.

.  A lightweight class type having value semantics. Explicitly “sealed”. Derived from System.  May define any no. Stack allocated entity.Value type. of parameterized constructors (no argument ctor is reserved). Can establish the value of each field during the time of construction.      Structures can implement any number of interfaces.CTS Structure types. Structure Inheritance is not allowed.

// can contain fields. } public bool IsChanged( ) { return false. { Console.Example for C# Structure           // Create a C# structure. Struct Baby // Structure : { public string name. public Baby(string name) // can contain ctors (with args).WriteLine(“Waaaaaaaaah! ! !”). } public bool IsSleeping( ) { return false. } public void Cry( ) // may take methods. { this. } } .name = name .

Allows derivation from multiple base interfaces. Not even derive from System.C# Interface Types  Named collection of abstract member definitions. Do not derive a common base interface such as IUnknown.      . It’s a pure protocol & do not provide an implementation. Allows polymorphism on implementation using class or struct. implemented by a given class or structure.Object.

& transform the underlying name/value pairs at runtime.     Default storage for each item is System. Derive from a common base class System. Public enum PlayerType { Wizard = 100. manipulate. .CTS Enumeration Types  Groups name/value pairs under a specific name. // A C# enumeration. Fighter = 200. Thief = 300 } .Enum Allows extract.Int32 Default storage slot can be altered if needed.

  .MulticastDelegate.NET event protocol. Delegate : class that derives from System. Intrinsic support for multicasting & asynchronous method invocations.NET) <=> type safe C style function pointer. Provide foundation for the .CTS Delegate Types  Delegate (.   Use: One entity to forward a call to another entity.

field. Abstract : to enforce polymorphic behavior.CTS Type Members   Each type may take any number of members. constant. “Visibility” trait (public. event } & associated with various “Adornments”. static constructor. Static : bound at class level entities. Virtual : to define a canned (but overridable) implementation. private. protected..g. internal). method.       instance : bound at object level entities. operator. Intrinsic CTS Data Types.doc . A type member is constrained by the set {constructor. nested type. property. E.

how to use static types etc. how to implement enum. CLS Rule 6). the minimal & complete set of features.g. Other rule: describes how a given language must represent text strings.. CLS = Physical subset of the full functionality defined by CTS Each rule with simple name (e. Rule 1: CLS rules apply only to those parts of a type that are exposed outside the defining assembly.. Accessed in a uniform manner by all . Support to produce code that can be hosted by the CLR.NET-aware languages.       .Understanding the CLS  Set of guidelines describe in vivid detail.

Above line of code will instruct the C# compiler to check your code for complete CLS compliance.    .CLSComplaint(true)] Attribute-based programming. Compiler error & description of the offending code on nonCLS-compliant syntactic tokens discovery.Ensuring CLS Compliance   // Tell the C# compiler to check for CLS compliance [assembly: System.

dll in VB6. JVM in Java. E. Common Object Runtime Execution Engine = mscoree.    . mfc42. .dll is loaded which in turn loads the required assembly into memory.NETaware languages & platforms.NET Runtime: Single well-defined CLR shared by all .Understanding the CLR  Runtime: Collection of external services required to execute a given compiled unit of code.0. msvbvm60.dll On Assembly referencing mscoree.g.dll in MFC..

Tasks of CLR   Resolve the location of an Assembly. Load the type in memory (both custom types & .     . Find the requested type within the binary by reading the requested metadata.NET BCL – mscorlib. Executes the code in question. Perform any (optional) security checks.dll) Compile the associated CIL into platform-specific instructions.

NET Source Code from Some .NET Compiler DLL or EXE Assembly (CIL. Metadata.NET Execution Engine (mscoree.dll & so Forth) Class Loader Jitter Platform-Specific Instructions Execute the application ! .dll in action Your .Mscoree.dll) Base Class Libraries (mscorlib.NET-Aware Language Some . and Manifest) .

Namespace: Collection of all the types in a binary in an organized manner. CLR-Languages use the same namespaces & same types as a C# developer.NET Imports System.NET #using namespace System. Use existing types from ..g. E. using System. No C# class library. //MC++  .NET Namespaces        No predefined set of language-specific class. //C#..NET Framework. // VB.

Data.Collections System.Data. Namespaces are a way to group semantically related types under a single name.Data System.Oledb System.SqlClient System.Data.Drawing .Diagnostics System..NET Namespaces           “System” Root namespace for all.Common System. System System.

Drawing2D System.Reflection.Runtime.Web System.IO System.             System.Windows.Xml .Emit System.Forms System.Threading System.Runtime.Security System.Reflection System.Net System.Drawing.Drawing.Printing System.Remoting System.InteropServices System.

using System.Accessing a Namespace Programmatically           using System. using System.Windows.Drawing. using System. //Explicitly list the namespaces used by this file. class MyClass { .Data. using System.OleDb.Data. using System.Drawing.Forms. using System.

Drawing. System. 20).       public void DoIt() { Bitmap bm = new Bitmap(20. // OR fully qualified name without directly referencing.Bitmap bm = new System.Bitmap(20. } } . 20).Drawing.

Any Queries ? .

8802-08  90720/.3.9.8802-.02.31089   #0.824/:0 47010-0/0542039  '078433 !72./.310893.7 .439.830/4700 439.20 8802- 0 .425480/41.708.$300 :9108802-08 30 94 430.8802- 90:3/073/4700-3. 2.8802-2.3  209..0 :910.47708543/03..439.8305.0-09003.324/:00.90/24/:08.7 47 %/ -3.31089     . %.8802-08 3:2074:8 %.724/:0.

884.75.4/0-.3897:.3:.91472850.9438 030198.943 $30.1..1.0.3:.09.91472 850.5.35.35.0 7:3 943.3:..90/ 49.943870.943809 4250702983897:.91472 .-4.90.0  #40.9898.70.:.03907.7/0884190 % .80 7:333433:2074:8 $ /0.3:.3:.3.79.42243390720/.0453.0.3897:.

9.7-0 909508.90.8202-078 574507908 2094/8 0.88 03:2  897:.7 .9 950...90 209.. 0. 09.209.9 /0130/390-3.42-30/ 9508 %8802- 1: . :80/- .07950 .7-080.:7. #40  8.70.9./.42507 -3.425090 .0 2..03 $07.3:..80.08...09.950  .07  2/ 00.0:80/94/08.9.71472./.30/93.35:..439.0398 410.3:./.

8802- 0  706:70/-9000./.:93.9..-43041 %#02493 7010.0  -0.4770..09.0/.9807.42507 390$0380 030198.74:84-0..9.7010703./.7-080. ..7-390.31089 8.439/ .8802-9801 84/08.90.09073..9-7483:9908 /0-:39448  -.943807.8802-944507./08.943 .209.9 &808.

:2039890894109073.74:8.4/0-7.31089 0.0-0037010703..07  24/:0/70....7.9:708/4.0/-90 00  .42507940307.31089 9/08.8802-089.08 .79801 98904-4190...9.8802-09073 8489890.8802-  .7-0890.79801 .84190-3.8802- 8 2.90789.9090.9 .

9438 %03.3/0//0.9438 %42507479907.7.4/0.9:708 84.3089/1107039. 3897:.7093# 47.91472 $50.4 2024703.!& 9.%.425089039420.4250/ 00.-094 $ ..:90/ 432.331: !&3897:..08.090708:983202478:9.3-0011..1.425394!..07..0.039%.425071470. $30.90.0 909907-006:550/94 7:393..

43897:..0 47.039502:89-0/0130/347/0794-04890/-90 # 9/0130834 41839..431472.9:70  39071.2:89 .70..9 9508 %95030399174290809.3.989.33:2-0741/893..9/08.08. .943 /00.0307..88 897:.9..7-084.1.03 %.90< %$8.3:.8802-$.42243%50$8902 %$ 3.9439.472.8802-2.42243850.349 -08:554790/-..3.92..439.0 03:207..

8 .80..425480/41.79:.48..-897..334 41202-078 %$..39071. ..88948:55479.882.9/0130.43/07.88.3.-0..9 202-0789.88%508 .830-..03.8808 %$2.0147/07.01742...0/ .%$.889508 %$.0147.7.88 4 2:9503079.542475.90789.

33491:3.8808.0/ 47349 $0..8  890.339071.80.0/.-...7...8..90789.0 .943.%$.88.882502039..88944907 9508  40890.88 $0.

9:807 %$./0. .90//70.8808.9574...9 .0/9508  43.70.48.08  890.3349-0/70.-897.8808..3-0..947...4397.88942502039.9202-0789..9-09003904-0.7090.90/ -:9.7090 -897.9.94341.70 30790/94/0130.43.478147/07. ....9.70.40.88.9 4-0..42243-0...334 4139071.-897.

88 .88.9890 .90 57490.%$.90789.431:70/9.8802- .9.90/ 39073.7.882:89-0.8 .8-9 ..439/  .-0:80/-09073.882...8802-08  47939..  01308190..8-9 4198... 57..997-:90  5:-..

%$$97:.40/ 5.3..90/0399 $97:.:0 950 $9.334 415.7..:0410.-890.9 80./0130.0/1742$8902 '..209070/ .33:2-074139071.9:703079.0/ .88950..9:708.3.7:2039.43897:.08349.43897:.9:709508 909.10//:739092041 .8 .08 $97:...4.943 07.:0802.32502039.947870807.3089...9478 34 ..39..0/ .

250147$97:..9:70 .

.

897:.9:70 $97:.9.90.- .70.

.

9:70  5:-.20 .$97:.89733.

.

.3.- 89733.20 .310/8 5:-..439..

.

9478 9.3...78 98 3.3.20< .439.203.

.

80< < .80< 5:-..4/7   43840 79030 .30/  709:731..-448... < 5:-..9....-448$0053  709:731..2.02094/8 5:-.

08 .03.0%508 .0.9202-07/0139438  25020390/-.4 /4349574..9 48/07.-897.42243-.8039071.03/07.8847897:.39071.01742$8902 -0.8&3343 490...5:7057494..08:.8039071./0.9 9 8..32502039.943 4854247582432502039.943:83...40.9:70 4349/07...94317422:950 -..20/.943 41.8847897:.

%$3:207.943%508 74:583.20.

1.3..:05.78:3/07..850.20 .

.

7/ 907 %01 < 01.:98947.943 !:-.42243-.3-0.20.03:2!.88$8902 3:2 48097.01470.07%50 .35:.01742.80.38147290:3/073 3.90  97.9 2.9070/1300/0/  07..0849.9028$8902 39 01..:98947....03:207.

:05.78.97:3920 ...

./014:3/.4.9438 !74...943543907 00.081742$8902 :9..94314790 %0.90 % 9508.9/07.108901:3.893 .90%508 00.90.7/.7434:82094/ 3.8900...90 &80 30039994147.83.94.889.03957494.349070399 39738.4 .%$00.8:554791472:9.

947 30890/950 4507.-0 2502039.077/. 94/0130.947 89.0 -4:3/.947 2094/ 5745079 10/  .039< .9..0.%$..90 57490.90.943 $9.43897.880.%508 /4.9..330/ -:94..9.9.0039908 39738.884.90/9.90/ 39073.99403147.33:2-0741202-078 950202-07 8.43897:.0039908 389.74:8 /47320398    '8-9 97.0542475... .94-0. 57..30/-90809.3.9 5:-.4389.-0.%$%5002-078 .9. ..-4:3/..43897:.9502. -897.39 0.47 '79:.

4250908094110..9:708 $:5547994574/:.9. % ..02:89705708039909 89738 494250203903:2 494:8089.943.70.&3/0789.79841.  .9509...:314722.3-04890/-90# .3:.20 0  $#:0 #:0 $7:08.//09.7-03.3307-.03.3:.70 05480/4:98/090/0133.7:0982503.55439494805..9.4/09..9.7-084.0880/3. 90232..  .3/390$ $0941:/0308/08.9/0130/-%$ .8:-809 41901:1:3.950809.08 $!8.8802- 9077:0/08.0.

3.38:73$425.0 .

.

75943419041103/3.03041.425090$.0  4250707747 /08.425.39 97:0 ( 997-:90 -.3.990.223 -4.4.0.3.4250794.07 .4/043343 $ .4250794.147$.425.9.0 .80/5747.39839.%090..94038/8.4:7 .0.425.4/0147.4/03897:.8802-$8902 $425.

328./890706:70/.4700 /84./0/.70 . 28.4/0   21.:94333028.03.&3/0789.8802-39420247 ..4700 / 38802-7010703.08 5.3:..9#:39200.39:73 4.9434109073.:90. /3 '3 .-.4250/:3941..70/-.807.914728 42243 -0.3/390# #:392040.08706:70/9400. % .2 /3' %#:3920 $300 /0130/#8. ..

1..47- / 425090./90950320247 -49. 4.0.9.94341.8 0.91472 850.3 45943.7-70.8841# #084.4/036:08943 .:79. 80.9438 !071472./390 706:0890/209.38802- 3/90706:0890/9509390-3.. 3897:.0904.:90890.%./.:89429508  % 28.884.90/3945.

.04/0 1742$420 % .3897:.31089 %0.884..91472 $50.55.9..4700 /3.708 28.4700 / .70 ./.:9090.3/.88 -7.9438 0.0 $420 % 42507 478802-  09.8.:943 330 28.1.943 .80.47- / 84479 ./07 9907 !.943 4:7 % $4:7.3:.

-3.203.30/2.1...9095083.3:.08:80908.2085..7 &80089395081742 %7..88 4.04507   :83$8902 . %.2047 .3 47.3307 # .3:.88-7.94341.73...0 40.209508.0 850. /0.2085.8.2085.08 4570/0130/80941.08 8.

.

 % 254798$8902 .

.

0$8902 .2085.' % :833..

.

 .

90/9508 :3/07.. 42243 $8902 . $6039 $8902 .9.2085.2085.3489.8303.39..70.08 $8902 #4493.. %.8 $8902 7.. .9474:5802.9. $8902 .70.3 .0147.08.9.9438 $8902 .2085..20 $8902 $8902 40. 0/$8902 .9.

$8902 7.943 29 $8902 #:3920 390745$07.943 $8902 #010./3 $8902 0$8902 3/48 4728 $8902 2 .08 $8902 #:3920 #02493 $8902 $0.:79 $8902 %70.3 !7393 $8902  $8902 09 $8902 #010..3 $8902 7.3 7.

. :83$8902 .9.22..0883..9.9. 0- .. :83$8902 :83$8902 7.2085.3 :83$8902 3/48 4728 :83$8902 .0!747..

.

3 .08:80/-9810 :83$8902 :83$8902 7.5..989903.88  ..88.2085.

5:-.4/49  92.5    ..5-23092.

.

3 92.3 $8902 7.5-230 $8902 7.2094:9/70.5    < < .97010703.10/3.3 92. #1:6:.

3":0708 .

Sign up to vote on this title
UsefulNot useful