Presentation is loading. Please wait.

Presentation is loading. Please wait.

Assemblies & Namespaces1. 2 Assemblies (1).NET applications are represented by an assembly An assembly is a collection of all software of which the application.

Similar presentations


Presentation on theme: "Assemblies & Namespaces1. 2 Assemblies (1).NET applications are represented by an assembly An assembly is a collection of all software of which the application."— Presentation transcript:

1 Assemblies & Namespaces1

2 2 Assemblies (1).NET applications are represented by an assembly An assembly is a collection of all software of which the application consists The Unit of Deployment, i.e. you need an assembly to install an application It is normally an executable file (.exe), or a dynamic link library file (.dll) Each assembly contains an assembly manifest, which is similar to a table of contents for the assembly. It contains information about the assembly (such as name, version), a list of files that are in this assembly, and a list of external references, etc.

3 Assemblies & Namespaces3 Assemblies (2) Project Properties Common Properties Configuration Properties Debug configuration: used by developer during development and testing, contains information for debugging Release configuration: debugging info is removed, better performance

4 Assemblies & Namespaces4 Namespaces (1) A software project may consist a number of pieces of code, components of an assembly To ease the use of these components, they are grouped into to Namespace A namespace is a group of components that are somehow related, these components can be type declarations, constants, procedures, functions, classes… Namespaces also resolve naming ambiguity issues (two methods with same name WriteError() in different libraries) Each assembly consists of a root namespace that contains all the components in the assembly, by default has the same name as the assembly. New namespaces can be defined under the root namespace using the Namespace keyword

5 Assemblies & Namespaces5 NamespaceExample (1) Namespace NSEx1 Public Module ModMain Sub Main() ' test the two methods Println("Called with Println() from NSEx1") NSEx2.Println("Called with NSEx2.Println() from NSEx1") System.Console.In.ReadLine() End Sub ' Write the message to the console Public Sub Println(ByVal message As String) System.Console.Out.WriteLine("Println() in NSEx1: " & message) End Sub End Module End Namespace

6 Assemblies & Namespaces6 NamespaceExample (2) Namespace NSEx2 Public Module ModAux Public Sub Println(ByVal message As String) System.Console.Out.WriteLine("Println() in NSEx2: " & message) End Sub End Module End Namespace

7 Assemblies & Namespaces7 Two Modules are defined under two different namespaces NSEx1 and NSEx2 Both modules have a method Println() To access a component declared in another namespace, you need to prefix it with the name of its namespace. e.g. NSEx2.Println() An important aspect of namespaces is that they allow only certain components to be exported and used by external code, by the Public, Private keywords. i.e. Encapsulation

8 Assemblies & Namespaces8 NamespaceExample (3)

9 Assemblies & Namespaces9 NamespaceExampleClient (1) Add Project, Add Reference Imports NamespaceExampleLib Imports NamespaceExampleLib.NSEx2 Module Module1 Sub Main() Dim s As String Do System.Console.Out.WriteLine("Enter some text and press ENTER") System.Console.Out.WriteLine("(leave empty and press ENTER to end)") s = System.Console.In.ReadLine() NSEx1.Println(s) ' calling Println() in NSEx1 NSEx2.Println(s) ' calling Println() in NSEx2 Println(s) ' calling Println() in NSEx2, as NSEx2 is imported Loop Until s.Length = 0 End Sub End Module

10 Assemblies & Namespaces10 You can’t import Imports NamespaceExampleLib.NSEx1 Imports NamespaceExampleLib.NSEx2 Compiler will complain

11 Assemblies & Namespaces11 Useful Namespaces (1) System: fundamental types, utility classes System.Collections: most commonly used collection classes such as arrays, lists, hash-tables, queues, stacks, etc. System.Data: data manipulation when interacting with external data storage System.Diagnostics: for debugging, testing and performance-monitoring System.DirectoryServices: provides access to Active Directory Services System.Drawing: graphics functions System.IO: read/write to streams

12 Assemblies & Namespaces12 Useful Namespaces (2) System.Messaging, System.Net: enable programs to communicate with other programs on different machines using messages and network protocols System.Runtime: for runtime support, contains other specialized namespaces for remoting, serialization, compiler, and interoperability services System.Security: to provide security and cryptography services System.Text: for parsing, encoding, and decoding of text streams, and together with System.Xml namespace is used to handle XML documents

13 Assemblies & Namespaces13 Useful Namespaces (3) System.Threading, System.Timer: offer access to operating system-level functions regarding thread handling and timer components System.Web: for developing and deploying Web-enabled applications System.Windows.Forms: GUI development Microsoft.VisualBasic: contains a large number of useful enumerations, structures, functions used in Visual Basic


Download ppt "Assemblies & Namespaces1. 2 Assemblies (1).NET applications are represented by an assembly An assembly is a collection of all software of which the application."

Similar presentations


Ads by Google