Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.

Similar presentations


Presentation on theme: "Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating."— Presentation transcript:

1 Module 3: Working with Components

2 Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating a Simple Console Client Creating an ASP.NET Client

3 An Introduction to Key.NET Framework Development Technologies Windows Forms Web Forms XML Web Services

4  Creating a Simple.NET Framework Component Using Namespaces and Declaring the Class Creating the Class Implementation Implementing Structured Exception Handling Creating a Property Compiling the Component

5 Using Namespaces and Declaring the Class Create a New Namespace Declare the Class using System; namespace CompCS {...} using System; namespace CompCS {...} public class StringComponent {...}

6 Creating the Class Implementation Declare a Private Field of Type Array of String Elements Create a Public Default Constructor Assign the stringSet Field to an Array of Strings stringSet = new string[] { "C# String 0", "C# String 1",... }; stringSet = new string[] { "C# String 0", "C# String 1",... }; private string[] stringSet; public StringComponent() {...}

7 Implementing Structured Exception Handling Implement the GetString Method Create and Throw a New Object of Type IndexOutOfRangeException Exceptions May Be Caught by the Caller in try, catch, finally block Structured Exception Handling Replaces HRESULT-Based Error Handling in COM public string GetString(int index) {...} if((index = stringSet.Length)) { throw new IndexOutOfRangeException(); } return stringSet[index]; if((index = stringSet.Length)) { throw new IndexOutOfRangeException(); } return stringSet[index];

8 Creating a Property Create a Read-Only Count Property to Get the Number of String Elements in the stringSet Array public int Count { get { return stringSet.Length; } } public int Count { get { return stringSet.Length; } }

9 Compiling the Component Use the /target:library Switch to Create a DLL Otherwise, an executable with a.dll file extension is created instead of a DLL library csc /out:CompCS.dll /target:library CompCS.cs

10 Lab 3.1: Creating a.NET Framework Component

11  Creating a Simple Console Client Using the Libraries Instantiating the Component Calling the Component Building the Client

12 Using the Libraries Reference Types Without Having to Fully Qualify the Type Name If Multiple Namespaces Contain the Same Type Name, Create a Namespace Alias to Remove Ambiguity using CompCS; using CompVB; using CompCS; using CompVB; using CSStringComp = CompCS.StringComponent; using VBStringComp = CompVB.StringComponent; using CSStringComp = CompCS.StringComponent; using VBStringComp = CompVB.StringComponent;

13 Instantiating the Component Declare a Local Variable of Type StringComponent Create a New Instance of the StringComponent Class CompCS.StringComponent myCSStringComp = new CompCS.StringComponent(); CompCS.StringComponent myCSStringComp = new CompCS.StringComponent();

14 Calling the Component Iterate over All the Members of StringComponent and Output the Strings to the Console for (int index = 0; index < myCSStringComp.Count; index++) { Console.WriteLine (myCSStringComp.GetString(index)); } for (int index = 0; index < myCSStringComp.Count; index++) { Console.WriteLine (myCSStringComp.GetString(index)); }

15 Building the Client Use the /reference Switch to Reference the Assemblies That Contain the StringComponent Class csc /reference:CompCS.dll,CompVB.dll /out:ClientCS.exe ClientCS.cs csc /reference:CompCS.dll,CompVB.dll /out:ClientCS.exe ClientCS.cs

16 Lab 3.2: Creating a Simple Console-Based Client

17 Demonstration: Creating a Windows Forms Client

18  Creating an ASP.NET Client Writing the HTML for the ASP.NET Application Coding the Page_Load Event Handler Generating the HTML Response

19 Multimedia: ASP.NET Execution Model

20 Writing the HTML for the ASP.NET Application Specify Page-Specific Attributes Within a Page Directive Import the Namespace and the Physical Assembly Specify Code Declaration Blocks... //client code... //client code

21 Coding the Page_Load Event Handler void Page_Load(Object sender, EventArgs EvArgs) { StringBuilder Out = new StringBuilder(""); int Count = 0; // Iterate over component's strings and concatenate Out.Append("Strings from C# Component "); CompCS.StringComponent myCSStringComp = new CompCS.StringComponent(); for(int index = 0; index < myCSStringComp.Count; index++) { Out.Append(myCSStringComp.GetString(index)); Out.Append(" "); } Message.InnerHtml = Out.ToString(); } void Page_Load(Object sender, EventArgs EvArgs) { StringBuilder Out = new StringBuilder(""); int Count = 0; // Iterate over component's strings and concatenate Out.Append("Strings from C# Component "); CompCS.StringComponent myCSStringComp = new CompCS.StringComponent(); for(int index = 0; index < myCSStringComp.Count; index++) { Out.Append(myCSStringComp.GetString(index)); Out.Append(" "); } Message.InnerHtml = Out.ToString(); }

22 Generating the HTML Response Specify the Body of the HTML Response

23 Demonstration: Testing the ASP.NET Client

24 Lab 3.3: Calling a Component Through an ASP.NET Page

25 Review An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating a Simple Console Client Creating an ASP.NET Client


Download ppt "Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating."

Similar presentations


Ads by Google