Introduction to .NET Manuel Costa manuelc@microsoft.com Academic Computer Science Program Manager manuelc@microsoft.com
What is .NET? A development platform: interfaces, components and tools to develop software The biggest change in the Microsoft platform since Windows NT replaced DOS Changes include: Code formats, compilers, Code loading and execution models, Security model, Object model, metadata, remoting protocols Class libraries, …
.NET: Principles The Microsoft Vision for Computing Make Internet-scale distributed computing ubiquitous Exploit inexpensive cycles and bandwidth Seamless integration of multiple applications and devices Deliver software as a service Next generation user experience The .NET Framework is the programming-model substrate for the .NET vision
Common Language Runtime .NET Framework Common Language Runtime (CLR) Multi-language support Common type system Simplified deployment Code Access Security Rich Class libraries Powerful, Consistent Programming Model Focus on code, not plumbing Built for Tools Support for design-time functionality Debugging, profiling, instrumentation support ASP.NET Web Forms Web Services Mobile Devices Windows Forms ADO.NET and XML Base Class Library Common Language Runtime
Common Language Runtime DEVELOPMENT Assembly public static void Main(String[] args ) usr=Environment.GetEnvironmentVariable("USERNAME"); try { { String usr; FileStream f; StreamWriter w; w.WriteLine(usr); w=new StreamWriter(f); f=new FileStream(“C:\\test.txt",FileMode.Create); Console.WriteLine("Exception:"+e.ToString()); } catch (Exception e){ w.Close(); } Compiler public static void Main(String[] args ) usr=Environment.GetEnvironmentVariable("USERNAME"); try { { String usr; FileStream f; StreamWriter w; w.WriteLine(usr); w=new StreamWriter(f); f=new FileStream(“C:\\test.txt",FileMode.Create); Console.WriteLine("Exception:"+e.ToString()); } catch (Exception e){ w.Close(); } Source code C# J# VB Cobol … CIL Metadata Resources
Common Language Runtime Compiler Assembly DEVELOPMENT C# J# VB Cobol … CIL Metadata Resources public static void Main(String[] args ) usr=Environment.GetEnvironmentVariable("USERNAME"); try { { String usr; FileStream f; StreamWriter w; w.WriteLine(usr); w=new StreamWriter(f); f=new FileStream(“C:\\test.txt",FileMode.Create); Console.WriteLine("Exception:"+e.ToString()); } catch (Exception e){ w.Close(); } Source code Assembly DEVELOPMENT DEPLOYMENT Global Assembly Cache (GAC) Install Setup Copy Browser Application Directory Download Cache
Common Language Runtime Assembly DEVELOPMENT Application Directory Setup Copy Browser Download Cache DEPLOYMENT Global Assembly Cache (GAC) Assembly on Target Machine Install Policy <security> <mscorlib> <configuration> <?xml version="1.0" encoding="utf-8" ?> <policy> version="1" <CodeGroup class="UnionCodeGroup" <PolicyLevel version="1"> PermissionSetName="Nothing" Description="Code group grants no permissio ns and forms the root of the code group tree."> Name="All_Code" <IMembershipCondition clas s="AllMembershipCondition" version="1"/> PermissionSetName="FullTrust" EXECUTION IL to Native Compiler Class Loader Security Assembly Loader Garbage Collection Native .exe + GC table Code Manager Exception Manager Thread Support COM Interop Debug Engine
Demo CLR
.NET Framework Namespace System.Web System.WinForms Services UI Design ComponentModel Description HtmlControls Discovery WebControls Protocols System.Drawing Caching Security Drawing2D Printing Configuration SessionState Imaging Text System.Data System.Xml ADO SQL XSLT Serialization Design SQLTypes XPath System Collections IO Security Runtime InteropServices Configuration Net ServiceProcess Remoting Diagnostics Reflection Text Serialization Globalization Resources Threading
.NET Framework Design Goals Simplify application development Provide a robust and secure execution environment Support multiple programming languages Simplify deployment and management
Simplify Development Windows API .NET Framework HWND hwndMain = CreateWindowEx( 0, "MainWinClass", "Main Window", WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, (HWND)NULL, (HMENU)NULL, hInstance, NULL); ShowWindow(hwndMain, SW_SHOWDEFAULT); UpdateWindow(hwndMain); .NET Framework Form form = new Form(); form.Text = "Main Window"; form.Show();
Simplify Development Organization Unified type system Code organized in hierarchical namespaces and classes Unified type system Everything is an object, no variants, one string type, all character data is Unicode Component Oriented Properties, methods, events, and attributes are first class constructs Design-time functionality
Robust And Secure Automatic lifetime management All .NET objects are garbage collected No stray pointers, no circular references Code correctness and type-safety IL can be verified to guarantee type-safety No unsafe casts, no uninitialized variables, no out-of-bounds array indexing Evidence-based security Based on origin of code as well as user Extensible permissions
Multi-Language Platform The freedom to choose language All features of .NET platform available to any .NET programming language Application components can be written in multiple languages Debuggers, profilers, code coverage analyzers, etc. work for all languages Available Compilers From Microsoft: VB, C++, C#, JScript, Java From other companies/universities: APL, COBOL, Eiffel, Fortran, Haskell, ML, Perl, Python, RPG, Scheme, Smalltalk, …
Unify Programming Models .NET Framework Consistent API availability regardless of language and programming model VB Forms RAD, Composition, Delegation MFC/ATL Subclassing, Power, Expressiveness ASP Stateless, Code embedded in HTML pages Windows API
Broad Language Support Dim s as String s = "authors" Dim cmd As New SqlCommand("select * from " & s, sqlconn) cmd.ExecuteReader() VB.NET string s = "authors"; SqlCommand cmd = new SqlCommand("select * from "+s, sqlconn); cmd.ExecuteReader(); C# C++ String *s = S"authors"; SqlCommand cmd = new SqlCommand(String::Concat(S"select * from ", s), sqlconn); cmd.ExecuteReader();
Broad Language Support J# String s = "authors"; SqlCommand cmd = new SqlCommand("select * from "+s, sqlconn); cmd.ExecuteReader();
Broad Language Support var s = "authors" var cmd = new SqlCommand("select * from " + s, sqlconn) cmd.ExecuteReader() JScript String *s = S"authors"; SqlCommand cmd = new SqlCommand(String::Concat(S"select * from ", s), sqlconn); cmd.ExecuteReader(); Perl s = "authors" cmd =SqlCommand("select * from " + s, sqlconn) cmd.ExecuteReader() Python
Broad Language Support ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. CLASS SqlCommand AS "System.Data.SqlClient.SqlCommand" CLASS SqlConnection AS "System.Data.SqlClient.SqlConnection". DATA DIVISION. WORKING-STORAGE SECTION. 01 str PIC X(50). 01 cmd-string PIC X(50). 01 cmd OBJECT REFERENCE SqlCommand. 01 sqlconn OBJECT REFERENCE SqlConnection. PROCEDURE DIVISION. *> Establish the SQL connection here somewhere. MOVE "authors" TO str. STRING "select * from " DELIMITED BY SIZE, str DELIMITED BY " " INTO cmd-string. INVOKE SqlCommand "NEW" USING BY VALUE cmd-string sqlconn RETURNING cmd. INVOKE cmd "ExecuteReader". Cobol
Broad Language Support RPG DclFld MyInstObj Type( System.Data.SqlClient.SqlCommand ) DclFld s Type( *string ) s = "authors" MyInstObj = New System.Data.SqlClient.SqlCommand("select * from "+s, sqlconn) MyInstObj.ExecuteReader() assembly_external(name="System.Data.SqlClient.SqlCommand") sqlcmdcharacter*10 xsqlcmd Cmd x='authors' cmd = sqlcmd("select * from "//x, sqlconn) call cmd.ExecuteReader() end Fortran
Broad Language Support APL s←String.New ‘authors’ cmd←SqlCommand.New (‘select * from ‘,s.ToString σ) sqlconn cmd.ExecuteReader |s| := 'authors'. |cmd| := SqlCommand('select * from '+s, sqlconn). cmd.ExecuteReader(). Smalltalk
Broad Language Support (let* ( (s "authors") (cmd (new-SqlCommand (string-append "select * from " s) sqlconn))) (execute-command cmd)) Scheme local s: STRING cmd: SQLCOMMAND do s := "authors" create cmd("select * from " + s, sqlconn) cmd.ExecuteReader() end Eiffel ExecuteReader = invoke System.Data.SqlClient.ExecuteReader(); SqlCommand = create System.Data.SqlClient.SqlCommand(String,\ System.Data.SqlClient.SqlConnection); query = sqlconn -> let{ s = "authors"; } in { cmd <- SqlCommand ("select * from "+s, sqlconn); cmd # ExecuteReader(); }; Mondrian
Demo Language Integration