module 3: working with components. overview an introduction to key.net framework development...
TRANSCRIPT
![Page 1: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/1.jpg)
Module 3: Working with Components
![Page 2: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/2.jpg)
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
![Page 3: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/3.jpg)
An Introduction to Key .NET Framework Development Technologies
Windows Forms
Web Forms
XML Web Services
![Page 4: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/4.jpg)
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
![Page 5: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/5.jpg)
Using Namespaces and Declaring the Class
Create a New Namespace
Declare the Class
using System;
namespace CompCS {...}
using System;
namespace CompCS {...}
public class StringComponent {...}public class StringComponent {...}
![Page 6: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/6.jpg)
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;private string[] stringSet;
public StringComponent() {...}public StringComponent() {...}
![Page 7: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/7.jpg)
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) {...}public string GetString(int index) {...}
if((index < 0) || (index >= stringSet.Length)) {throw new IndexOutOfRangeException();
}return stringSet[index];
if((index < 0) || (index >= stringSet.Length)) {throw new IndexOutOfRangeException();
}return stringSet[index];
![Page 8: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/8.jpg)
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; }}
![Page 9: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/9.jpg)
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.cscsc /out:CompCS.dll /target:library CompCS.cs
![Page 10: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/10.jpg)
Lab 3.1: Creating a .NET Framework Component
![Page 11: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/11.jpg)
Creating a Simple Console Client
Using the Libraries
Instantiating the Component
Calling the Component
Building the Client
![Page 12: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/12.jpg)
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;
![Page 13: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/13.jpg)
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();
![Page 14: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/14.jpg)
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));
}
![Page 15: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/15.jpg)
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
![Page 16: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/16.jpg)
Lab 3.2: Creating a Simple Console-Based Client
![Page 17: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/17.jpg)
Demonstration: Creating a Windows Forms Client
![Page 18: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/18.jpg)
Creating an ASP.NET Client
Writing the HTML for the ASP.NET Application
Coding the Page_Load Event Handler
Generating the HTML Response
![Page 19: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/19.jpg)
Multimedia: ASP.NET Execution Model
![Page 20: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/20.jpg)
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
<%@ Page Language="C#" Description="ASP.NET Client" %><%@ Page Language="C#" Description="ASP.NET Client" %>
<%@ Import Namespace="CompCS"%><%@ Import Namespace="CompVB"%>
<%@ Import Namespace="CompCS"%><%@ Import Namespace="CompVB"%>
<script language="C#" runat=server>... //client code
</script>
<script language="C#" runat=server>... //client code
</script>
![Page 21: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/21.jpg)
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<br>"); CompCS.StringComponent myCSStringComp = new CompCS.StringComponent(); for(int index = 0; index < myCSStringComp.Count; index++) { Out.Append(myCSStringComp.GetString(index)); Out.Append("<br>"); } 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<br>"); CompCS.StringComponent myCSStringComp = new CompCS.StringComponent(); for(int index = 0; index < myCSStringComp.Count; index++) { Out.Append(myCSStringComp.GetString(index)); Out.Append("<br>"); } Message.InnerHtml = Out.ToString();}
![Page 22: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/22.jpg)
Generating the HTML Response
<body> <span id="Message" runat=server/></body>
<body> <span id="Message" runat=server/></body>
Specify the Body of the HTML Response
![Page 23: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/23.jpg)
Demonstration: Testing the ASP.NET Client
![Page 24: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/24.jpg)
Lab 3.3: Calling a Component Through an ASP.NET Page
![Page 25: Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating](https://reader035.vdocuments.mx/reader035/viewer/2022062719/56649edb5503460f94beb908/html5/thumbnails/25.jpg)
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