Developer .NET UPDATE--Visual Studio 2005's Partial Classes--August 20, 2004

This Issue Sponsored By

Win a Harley at Microsoft ASP.NET Connections

In This Issue

1. Developer .NET Perspectives

  • Visual Studio 2005 Offers Partial Classes
  • 2. Resource

  • Featured Thread: Why Doesn't the CLR's CTS Define Syntax?
  • 3. New and Improved

  • Toolkit Reads, Writes, and Converts Images

  • 1. Developer .NET Perspectives

    by Bill Sheldon, [email protected]

  • Visual Studio 2005 Offers Partial Classes
  • In my last column "Anonymous Admirer" (, I introduced you to some new language-related features in Visual Studio 2005 beta 1. In this column, I want to focus on how the Windows .NET Framework is changing under the covers. Because of these infrastructure changes, Visual Basic .NET and C# support partial classes, which in turn, provides you with a richer development experience in Visual Studio 2005.

    In Visual Studio 2005, you can split the implementation of a specific class across multiple source files. A good comparison for this split is the way in which C++ splits the implementation of a class across two files: .h and .cpp. The header, or .h, file is generally associated with the declaration of the methods and properties used by the class, whereas the .cpp file is generally associated with the class's source code.

    In Visual Studio 2005, you use the Partial keyword in a class declaration to tell the compiler that the class implementation code has been split across several source files. The code is then combined during the compilation process.

    The best way to witness the effects of partial classes is to create a new Windows Form-based application in both Visual Studio 2005 and Visual Studio .NET 2003. Then, on each form, drop a single control, such as a button. If you open the code view of the Windows Form in Visual Studio .NET 2003, you'll notice all the stock code to implement this button at the top of the source file. Trying to navigate through all that generated code with custom event handlers can be a pain. But if you open the code view of the Windows Form in Visual Studio 2005, all you'll find is a simple declaration along the lines of

    Public Class Form1
    End Class

    Gone is the stock code that clutters up the source files of classes in Visual Studio .NET 2003.

    To find the form's generated logic in Visual Studio 2005, you need to look elsewhere because of the use of partial classes. Open Solution Explorer, which shows you the default view of the objects that make up your projects. One of Solution Explorer's options is to "Show All Files." This option lets you see not only the top-level elements in your project but also every file that exists in your project. When you select this option, you'll find two new files underneath the form's source file. If you open the file that has a name similar to Form1.Designer.vb, you'll find all the stock code. At the top of the class code is the partial keyword, which tells the compiler that this code is a partial implementation of a class.

    The partial keyword, however, doesn't need to be included with every source file for a class; one file can be declared without this keyword. However, I think this practice is a bad idea. I believe the keyword should be required in every file that's part of a partial class because this keyword would let you know that there's additional source code associated with a class. In a maintenance scenario in which you're searching for a bug, you might not immediately realize that a class has more than one source file.

    As I mentioned previously, when you select the "Show All Files" option, Solution Explorer displays two new files underneath the source file. Besides Form1.Designer.vb, you'll find a resource file. Each Windows Form now comes with a unique resource file to which you can add graphics, audio bites, and strings that you want to associate with that form. Just like the partial keyword, the resource file provides a way for you to automatically partition the elements in your Windows Form source code. In my next column, I'll show you how this same idea of presenting a project as a collection of small units is changing ASP.NET.

    Sponsor: Win a Harley at Microsoft ASP.NET Connections e

    Microsoft, MSDN Magazine, and Tech Conferences come together November 7-10 in Las Vegas, NV to bring developers a conference that will rock the industry! Be among the first to uncover what INDIGO, Microsoft's code name for the next generation distributed application technology, is all about. Attendees will receive the latest build of Visual Studio 2005 and a beta copy of SQL Server 2005. Register now and attend sessions at VS Connections and SQL Server Magazine Connections FREE!

    (brought to you by SQL Server Magazine)

  • Attention SQL Server Magazine UPDATE Reader!

  • I You need SQL Server info! Subscribe to SQL Server Magazine today and save 30% off the cover price. You will also receive free access to the entire online article archive offering savvy tips, expert advice, endless code listings and much more -- get the answers you are looking for! Order now:

  • SqlJunkies Has What Developers Need

  • SqlJunkies is your online community resource for original tutorial and how-to articles for developing applications with SQL Server 2000 and Yukon; peer-to-peer help and networking through discussion forums and newsgroups; technology tips and pointers from expert bloggers; and the latest in SQL Server-related events and news.

    2. Resource

  • Featured Thread: Why Doesn't the CLR's CTS Define Syntax?
  • Novice forum member savanted1 is wondering why the Common Type System (CTS) in the Windows .NET Framework's Common Language Runtime (CLR) defines only semantics and not both syntax and semantics. If you know why, go to the following URL:

    Events Central
    (A complete Web and live events directory brought to you by Windows & .NET Magazine: )

  • Newest SQL Server Web Seminar: Performance Break-Throughs
  • Meeting database performance demands with larger amounts of data and more complex retrieval requirements is a constant challenge for SQL Server users. SQL Server Magazine invites you to attend a free, interactive Web seminar on September 16, 2004. Learn about the foundation of common issues and tactics for solving SQL Server performance dilemmas. Register today:

    3. New and Improved

  • Toolkit Reads, Writes, and Converts Images
  • AccuSoft released ImageGear for .NET, an imaging toolkit that provides numerous methods and properties to read, write, and convert images in more than 20 popular image formats. Providing full access to the file format metadata, this toolkit provides a fully managed .NET solution with no dependencies on outside native code. As a result, there are no extra DLLs to ship or ActiveX controls to register, which makes applications easier to deploy. Modules are available for reading and writing to PDF documents and JPEG2000-format images. Pricing starts at $1495. For more information, contact AccuSoft at 508-351-9092 or 800-525-3577.

    Contact Us

  • About Developer .NET Perspectives -- [email protected]
  • About the newsletter -- [email protected]
  • About technical questions --
  • About product news -- [email protected]
  • About your subscription -- [email protected]
  • About sponsoring an UPDATE -- contact Kate Silvertooth ([email protected])
  • This email newsletter is brought to you by Windows & .NET Magazine, the leading publication for IT professionals deploying Windows and related technologies. Subscribe today.

    View the Windows & .NET Magazine Privacy policy at

    Windows & .NET Magazine, a division of Penton Media, Inc.
    221 East 29th Street, Loveland, CO 80538
    Attention: Customer Service Department

    Copyright 2004, Penton Media, Inc. All Rights Reserved.

    Hide comments


    • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

    Plain text

    • No HTML tags allowed.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Lines and paragraphs break automatically.