- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
PS (10) > $intList[2].gettype().FullName System.Int32 in C#
PS (10) > $intList[2].gettype().FullName System.Int32 Code-39 Creator In C# Using Barcode generator for VS .NET Control to generate, create Code 39 Full ASCII image in .NET applications. www.OnBarcode.comCode-39 Decoder In C# Using Barcode decoder for .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comNow let s look at another example. This time we ll build a generic dictionary. Instantiating a generic dictionary A generic dictionary is like a hashtable; it s made up of key/value pairs, but we want to limit the keys to strings and the values to integers. Once again, we ll write a convenience function to handle the heavy lifting. Here s the function to do this: Drawing Barcode In C# Using Barcode encoder for .NET Control to generate, create Barcode image in .NET framework applications. www.OnBarcode.comPainting PDF-417 2d Barcode In Visual C# Using Barcode creation for .NET framework Control to generate, create PDF-417 2d barcode image in .NET applications. www.OnBarcode.comUSING .NET FROM POWERSHELL
Linear Barcode Generation In C# Using Barcode encoder for .NET Control to generate, create 1D Barcode image in .NET framework applications. www.OnBarcode.comMaking Data Matrix In C# Using Barcode printer for Visual Studio .NET Control to generate, create DataMatrix image in .NET framework applications. www.OnBarcode.comPS >> >> >> >> >> >> >>
UPC Code Generator In Visual C#.NET Using Barcode drawer for .NET framework Control to generate, create UPC Symbol image in VS .NET applications. www.OnBarcode.comEncode Leitcode In C#.NET Using Barcode encoder for Visual Studio .NET Control to generate, create Leitcode image in Visual Studio .NET applications. www.OnBarcode.com(11) > function New-GenericDictionary ([type] $keyType, [type] $valueType) { $base = [System.Collections.Generic.Dictionary``2] $ct = $base.MakeGenericType(($keyType, $valueType)) , (New-Object $ct) } Code 39 Decoder In VS .NET Using Barcode scanner for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comANSI/AIM Code 39 Generation In None Using Barcode generator for Word Control to generate, create Code 39 Full ASCII image in Word applications. www.OnBarcode.comAgain, start with the base type of the collection, followed by `2 because we have two type parameters this time. We pass the two type parameters to the function into the call to MakeGenericType() as an array. This will give us the closed type for the generic dictionary. Finally, we return an instance of the closed type. We ll use this function to build a dictionary that is constrained to permit only strings for keys and integers for the values. Draw EAN 128 In None Using Barcode printer for Office Word Control to generate, create EAN / UCC - 14 image in Office Word applications. www.OnBarcode.comPrint Barcode In VB.NET Using Barcode creation for .NET Control to generate, create Barcode image in .NET framework applications. www.OnBarcode.comPS (12) > $gd = New-GenericDictionary string int
Print Barcode In None Using Barcode printer for Software Control to generate, create Barcode image in Software applications. www.OnBarcode.comECC200 Scanner In C#.NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comLet s enter values and display the result: EAN128 Encoder In None Using Barcode encoder for Excel Control to generate, create EAN / UCC - 14 image in Office Excel applications. www.OnBarcode.comUPC - 13 Drawer In Java Using Barcode encoder for Java Control to generate, create EAN / UCC - 13 image in Java applications. www.OnBarcode.comPS (13) > $gd["red"] = 1 PS (14) > $gd["blue"] = 2 PS (15) > $gd Key --red blue Value ----1 2 Encoding EAN / UCC - 14 In Objective-C Using Barcode creator for iPad Control to generate, create UCC - 12 image in iPad applications. www.OnBarcode.comEncode Data Matrix In Objective-C Using Barcode generation for iPhone Control to generate, create DataMatrix image in iPhone applications. www.OnBarcode.comNext try to assign a nonstring key. This would work with a regular hashtable, but fails with the generic dictionary instance. Data Matrix Reader In VB.NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET applications. www.OnBarcode.comPrint Data Matrix In None Using Barcode generator for Online Control to generate, create Data Matrix 2d barcode image in Online applications. www.OnBarcode.comPS (16) > $gd[13] = 3 Array assignment to [13] failed: The value "13" is not of type " System.String" and cannot be used in this generic collection. Parameter name: key. At line:1 char:5 + $gd[1 <<<< 3] = 3 Also note that this time, the PowerShell type converter didn t try to convert to the target type. The type signature is too complex for it to figure out, so we ll have to explicitly cast the arguments. Finally, let s look at the full name of the type of object stored in $gd. PS (17) > $gd.gettype().FullName System.Collections.Generic.Dictionary`2[[System.String, mscorlib , Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e 089],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] PS (18) > CHAPTER 1 1
GETTING FANCY .NET AND WINFORMS
To reiterate the comment from the beginning of this section, very rarely will you need some of these esoteric capabilities, but when you do need them, they can be incredibly valuable. Enough with the .NET trivia challenge. In the remainder of this chapter, we ll look at how we can apply some of the things we ve learned to build more interesting applications. AUTHOR S NOTE
These examples are designed to demonstrate the range of tasks that can be addressed with PowerShell rather than be strictly practical. For some more purely practical examples using .NET in admin scenarios, take a look at appendix B. POWERSHELL AND THE INTERNET
In this section, we re going to put the network back into .NET. As one would expect from a modern programming environment, .NET (and consequently PowerShell) has a pretty comprehensive set of types for doing network programming. AUTHOR S NOTE
The .NET framework has good networking capabilities, but I suspect that the name came out of the marketing frenzy during the first Internet bubble: .NET 1.0 was released in 2001. At that time, people with calling everything dot-something. I m surprised we didn t end up with .Coke or Pepsi.NET or some other silliness. In this section, we ll look at a couple useful examples of doing network programming with the .NET networking types. 11.2.1 Example: Retrieving a web page The most common networking task in the Internet age is to download a web page. Here s how to do that in PowerShell using the [system.net.webclient] type. This is a type that provides common methods for sending data to and receiving data from websites (or anything else that can be addressed with a URL). In this example, we ll use this type to download data from the MSDN blog home page. First we need to create an instance of System.Net.WebClient:
|
|