Your Introduction to the My Object in VS 2005

VB can be a completely object-oriented language and still find ways to enhance productivity. One of the ways that Microsoft is still finding innovative ways to increase productivity without making VB.NET a second-class language is the introduction of the My object, which will ship in VS 2005 and is available in Beta 1 versions of VB 2005. This article introduces this new object.

Classes in My Object

My is an object like Me, but instead of being a self-referencing object it is a wrapper that makes getting at the advanced features of .NET easier. If you found using advanced features such as the ResourceManager and WebServices confusing, or even reading information from the AssemblyInfo file, then you are going to love My.

Note: The actual nomenclature for My is still being decided. Currently, the correct word to describe My is feature. It remains to be seen whether Microsoft will call My an object, namespace, or something else when it releases VS 2005.

My contains Application, Computer, Resources, User, and WebServices wrapper objects that act like shortcuts to powerful and useful features of .NET. You can use these features without creating instances of the classes they wrap and without mastering arcane subjects like reflection first. Don't misunderstand me: One should learn reflection because it is a powerful tool, but lowering the barrier to entry is a classic VB response to complex subjects.

Setting AssemblyInfo Information

Rather than try to cover everything My offers, I picked just one facet, the AssemblyInfo class, as a vessel for introducing this neat feature. The AssemblyInfo class is a wrapper for the AssemblyInfo.vb file that VB 2005 adds to every project. The AssemblyInfo class makes it easy to obtain information about your project, such as title, copyright, and version information. A classic use for this information is to create an About dialog for your Windows Forms applications.

Early versions of VB.NET used assembly-level attributes and code to incorporate things like version information into VB assemblies. In the new version, Microsoft created an easy-to-use dialog box (see Figure 1) that permits you to add assembly information to your .NET applications. You set this information by selecting Project|Properties from the menu. This opens your project properties dialog. In that dialog, select the Application tab and click the Assembly Information button. Simply fill out the dialog and click OK.

Figure 1: Add Assembly Information Using This Dialog Form

Reading My.Application.AssemblyInfo

Reading the assembly information has always been easier in VB than in C# because the Microsoft.VisualBasic.dll assembly is always part of your VB applications. In current editions of VB, you have to create an AssemblyInfo object, passing the executing assembly as a parameter. In VB 2005, all you have to do is access the ubiquitous My object, referring to My.Application.AssemblyInfo, and you have immediate, one-line access to your assembly's information (see Listing 1).

Listing 1: Access Information About an Assembly with a Single Line of Code

Module Module1

   Sub Main()
      Console.WriteLine(My.Application.AssemblyInfo.Title)
      Console.WriteLine(My.Application.AssemblyInfo.LegalCopyright)
      Console.WriteLine(My.Application.AssemblyInfo.Version.ToString())
      Console.ReadLine()
   End Sub

End Module

Ease of use is what VB always has been about. By building the new VB on top of the powerful .NET framework, VB can be both easy to use and powerful.

New VB 2005 Feature

The My object encapsulates many of the advanced features of .NET into a consolidated wrapper package that makes these features easier to access—often with a single line of code. Pick up a beta copy of VS 2005 today and you will discover My and many other new features that increase your productivity and enjoyment.

About the Author

Paul Kimmel is the VB Today columnist for www.codeguru.com and has written several books on object-oriented programming and .NET. Check out his book Visual Basic .NET Power Coding from Addison-Wesley and his upcoming book UML DeMystified from McGraw-Hill/Osborne (Spring 2005). Paul is also the founder and chief architect for Software Conceptions, Inc, founded 1990. He is available to help design and build software worldwide. You may contact him for consulting opportunities or technology questions at pkimmel@softconcepts.com.

If you are interested in joining, sponsoring a meeting, or posting a job, check out www.glugnet.org, the Web page of the Greater Lansing area Users Group for .NET.

Copyright © 2005 by Paul Kimmel. All Rights Reserved.



Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds