Geeks With Blogs

News
WinToolZone - Spelunking Microsoft Technologies
I work as a developer on the Common Language Runtime (CLR) team, specifically in the areas of exception handling and CLR hosting.
Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Post Categories

Inside and Out... An attempt to understand technology better...
One of the features of .NET Framework Whidbey is the concept of Partial Types. Before I talk about them, allow me to clarify right at the start that this concept is nothing more than compiler magic. There's no CLR support/modification for this. And by the time this blog ends, you will know understand that well enough.

The simple idea of Partial Types is to have a class or a structure definition/implementation split across multiple source files. Lets take an example of an assembly that you are designing and the implementation is spread across 1000s of lines in the same source file. Ideally, you would want to logically segregate the implementation, maybe functionally, and have your teams works upon the same independent of one another, across multiple source files. Today, this isn't possible.

However, with Whidbey, you can now do precisely this. You could have something like this:

// This is SMTP.CS
namespace WinToolZone
{
   partial public class Email
   {
      // SMTP implementation comes here
      void SendEmail() { ... }
    }
}

And have the POP3 implementation similar:

// This is POP3.CS
namespace WinToolZone
{
   partial public class Email
   {
      // POP3 implementation comes here
      void FetchEmail() { .... }
    }
}

As evident, these are two different files. Whidbey introduces a new keyword, partial, that tells the compiler that the implementation of this partial type is split across multiple files. When all the files are compiled, the compiler takes the implementation of the parital type from all the files where it is present and consoldiates them to form a representation that is functionally equivalent to the developer implementing them all together in a single file. Taking the example used above, the compiler's representation will be as follows:

namespace WinToolZone
{
   partial public class Email
   {
      // implementation comes here
      void SendEmail() {...}
      void FetchEmail() {...}
    }
}

Thus, the structure of the IL thus produced is no different than what it will be as it is produced today. Consequently, from the CLR's perspective, the IL is the same; whether produced using Whidbey or today's framework version. Thus, no changes in CLR exclusively for Partial Types. But you can now have the implementation split across multiple files, to be worked by developers independently.
Posted on Wednesday, May 12, 2004 11:20 AM .NET Framework | Back to top


Comments on this post: Partial Types

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Gaurav Khanna | Powered by: GeeksWithBlogs.net