Problem solve Get help with specific problems with your technologies, process and projects.

'My' extensions turbocharge new VB tool set

A brief run-down on what the new do-it-all namespace does can help you get moving with VB2005 applications.

My.Settings is a very useful new aspect of the .NET Framework 2.0. It is worthwhile to view this element of the My extensions in context, along with its other brethren. In fact, if there's an underappreciated workhorse in the new Visual Studio 2005 (and its equally new companion, the .NET Framework 2.0) it's got to be the many Visual Basic language extensions that fall under the My hierarchy in that environment. You can use My constructs for an amazing array of activities, as you'll shortly see.

A brief run-down on what this do-it-all namespace can do includes the following:

  • Supports advanced IDE features such as Edit and Continue, IntelliSense code snippets, and the Exception Assistant;
  • Supports advanced language enhancements such as generics, partial classes, and unsigned types; and
  • Works with .NET Framework enhancements to Windows Forms, data binding, and ClickOnce deployment, among others.

    A good example of what's possible may be revealed by exploring the My.Computer.FileSystem and other related classes, which some experts describe as a "speed-dial" for the .NET framework. For example, whereas some programmers may choose to use IO.StreamReader and its sr.ReadToEnd function to copy the contents of a text file into a string (which requires at least three lines of code), a single assignment statement using My will also do the job -- namely:

    Contents = My.Computer.FileSystem.ReadAllText("c:\mytextfile.txt")
    

    Understanding the basic organization of classes within My really helps to get a sense of the kinds of uses to which these language extensions are suited:

  • My.Application: This offers information about application information and services available, including a built-in logging facility.
  • My.Computer: Along with My.User, this permits easy navigation of services and data for the current host computer (this is where the FileSystem classes come into play, and where My.Computer.Ports, My.Computer.Network, and My.Computer.Printer are also available).
  • My.Forms: Use this to navigate and interact with forms available to your project.
  • My.Resources: Use this to inspect or interact with resources configured using other VB or VS.NET tools in advance, or added to your project.
  • My.Settings: Use this to inspect or interact with settings configured using other VB or VS.NET tools in advance, or added to your project.
  • My.User: Along with My.Computer, this permits easy navigation of services and data for the current host computer.
  • My.WebServices: Use this to navigate and interact with Web services referenced in a project.

    There's so much going on here that it will take some time to explore and learn the many capabilities (and time-saving techniques) available through My. You'll also find these MSDN articles helpful in that quest:

  • Visual Basic Developer Center Navigate the .NET Framework and Your Projects with "My" by Duncan Mackenzie.
  • Visual Studio 2005 Technical Articles My.Internals: Examining the Visual Basic My Feature

    But if you put in the time and effort, you can count on reaping some righteous rewards!


    Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT Certification and information security topics. E-mail Ed at etittel@techtarget.com with comments, questions, or suggested topics or tools to review.


  • Dig Deeper on .NET Framework 2.0 and Visual Studio 2005 development

    Start the conversation

    Send me notifications when other members comment.

    Please create a username to comment.

    -ADS BY GOOGLE

    SearchCloudComputing

    SearchSoftwareQuality

    TheServerSide.com

    Close