1 / 13

Assemblies & Namespaces

Learn about assemblies and namespaces in .NET applications, their importance in deployment and organization, and how to use them effectively. Explore various useful namespaces for different functionalities.

delsa
Download Presentation

Assemblies & Namespaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assemblies & Namespaces Assemblies & Namespaces

  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. Assemblies & Namespaces

  3. 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 Assemblies & Namespaces

  4. 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 Assemblies & Namespaces

  5. 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 Assemblies & Namespaces

  6. 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 Assemblies & Namespaces

  7. 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 Assemblies & Namespaces

  8. NamespaceExample (3) Assemblies & Namespaces

  9. 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 Assemblies & Namespaces

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

  11. 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 Assemblies & Namespaces

  12. 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 Assemblies & Namespaces

  13. 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 Assemblies & Namespaces

More Related