Search:
Locator+ Code:
FTPOnline Channels Conferences Resources Hot Topics Partner Sites Magazines About FTP RSS 2.0 Feed

Back to VSLive! San Francisco Show Daily Home

email article
printer friendly

How to Handle WMI Data in .NET
Learn what to do when WMI properties don't correspond to .NET data types.
by Ken Getz

VSLive! San Francisco, February 12, 2003

ADVERTISEMENT

Note: Ken Getz is presenting "Fill the Gaps With WMI" and "Save Yourself With .NET Serialization" at VBITS San Francisco, Wednesday, February 12. These tips are from those sessions.

When WMI Properties Don't Correspond to .NET Data Types
The WMI (Windows Management Instrumentation) designers didn't have .NET programmers in mind when creating their classes. You'll find that many WMI properties simply don't correspond to .NET data types directly. For example, although WMI supports an unsigned integer type, VB.NET does not. Sometimes you can fake it, using structures provided by .NET. In other cases, you'll need to turn off Option Strict in VB.NET to be able to handle the WMI data. If you find code that will simply not run with Option Strict on, you can segregate the "errant" code into its own module with Option Strict set to Off at the top of the module.

Exclude a Class Member When Serializing an Object
When you serialize an object, the serializer stores all the values associated with your object in the output stream, even private values. Because the goal of the serializers in .NET is to accurately allow you to save and restore the entire state of an object or set of objects, it's crucial that the serializer save all the data, not just the public data. If you want to explicitly exclude any member of the class when you serialize the object, add the NonSerializable attribute to the specific member. (This tip applies only to the SoapFormatter and BinaryFormatter classes—the XmlFormatter class doesn't store private data, as its purpose is to serialize data for use with XML Web Services, where private data wouldn't serve any purpose.)

About the Author
Ken Getz is a senior consultant with MCW Technologies and splits his time between programming, writing, and training. Ken has written many technical books, including ASP.NET Developer's Jumpstart with Paul D. Sheriff, and is co-author of several best-selling books, including the Access 2002 Developer's Handbooks and VBA Developer's Handbook. He co-wrote and recorded for video training several courses for Application Developer's Training Company (AppDev), including ADO.NET, VB.NET, ASP.NET, Access 2000 and 97, and VB6 seminars. You can reach Ken at keng@mcwtech.com, www.mcwtech.com, or www.developershandbook.com.

Back to top


Java Pro | Visual Studio Magazine | Windows Server System Magazine
.NET Magazine | Enterprise Architect | XML & Web Services Magazine
VSLive! | Thunder Lizard Events | Discussions | Newsletters | FTP Home