Developer .NET UPDATE--Visual Studio 2005's Partial Classes--August 20, 2004
Because of infrastructure changes in the Windows .NET Framework, Visual Basic .NET and C# support partial classes. This support means that you’ll have a richer development experience in Visual Studio 2005.
August 19, 2004
This Issue Sponsored By
Win a Harley at Microsoft ASP.NET Connections
http://www.devconnections.com
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" (http://www.winnetmag.com/windows/article/articleid/43549/43549.html), 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!
http://www.devconnections.com
Announcements
(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:
https://secure.pentontech.com/nt/sql/index.cfm?PromoCode=00ep2148ds
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.
http://www.SqlJunkies.com
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:
http://www.winnetmag.com/forums/rd.cfm?cid=55&tid=124367
Events Central
(A complete Web and live events directory brought to you by Windows & .NET Magazine: http://www.winnetmag.com/events )
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:
http://www.winnetmag.com/seminars/sqlPerformanceSolutions/index.cfm?code=0820dupdate
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.
http://www.accusoft.com
Contact Us
About Developer .NET Perspectives -- [email protected]
About the newsletter -- [email protected]
About technical questions -- http://www.sqlmag.com/forums
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 andrelated technologies. Subscribe today.
http://www.winnetmag.com/sub.cfm?code=wswi201x1z
View the Windows & .NET Magazine Privacy policy at
http://www.winnetmag.com/aboutus/index.cfm?action=privacy
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.
About the Author
You May Also Like