var blog = {
    author: "Burcu Dogan",
    author_dialects: ["Burcu Do\u011fan", "thejbf"],
    author_email: "burcu...@googlemail.com",
    author_representations: ["twitter", "google", "stumbleupon", "friendfeed", "stackoverflow"],
    post: {
	title: "An Unusual Proclaim: Partial Classes", 
        body:

WinDFSWhen it comes to the myth behind the partial classes (came along with C# 2.0  -  also added to VB.NET, fix me if I am wrong), what usually said is:

  1. Partial classes are great if multiple number of developers need to be working on the same class, or
  2. It helps you to separate generated code from your development. A typical example is ASP.NET pages or Win Forms applications.

These reasons are both true but according to my inner sense; but many overlook the real secret behind portioning of a class. A few weeks ago, I started to code a distributed file system (a virtual one – highly depends on the existing features of Windows) called WinDFS, and have to implement a message transmission engine over TCP/IP to serve communication among nodes. I decided to run it by remote objects, so do I created a serializable Transferable class that has a member of FileInfo. Both WinDFSClient and WinDFSMaster are referencing to the Remoting project for transmission operations. The straight-forward process flows like this: a client asks for metadata of a file/directory by sending the corresponding command with the entity’s path and an empty FileInfo element to the master machine. Master searches storage engine fills the FileInfo element with related data and sends it back to the requester node.

Everything is fine and enough up to this point. But what would you do if you want to play more with FileInfo specifically on clients – such as outputting the attributes of an instance of FileInfo as XML? Would it make sense to create a XmlOutputFromFileInfoBlahBlah class and make the solution looks like garbage? No, as long as we are not Christopher Millis.

The most natural way is to extend FileInfo specially for WinDFSClient, note that #1 best resolution has nothing to do with extending the original FileInfo in Remoting. An XML output most probably has nothing in common with other projects. On the other hand, XML outputting sounds like a stand-alone feature but what would we do if we wanted to expand FileInfo with resources WinDFSMaster uses.

At this point partial classes are great design choices. Well, at least it worked for me. I created a class in WinDFSMaster named FileInfo. Added partial keyword to the class signatures, implemented ToXml into the master and it works like a dream now. Masters are able to use FileInfo.ToXml() while it is totally isolated from other projects. Note that you have to have physical access to the source code of the initial class to take the advantage of this method.

,
        tags: ["", ""]
    },
    comments: [ /* 1 comment */
"Derek:

I wish partial classes were supported for system libraries with different access levels. Your application would be very cool to extend existing classes, like String etc.

(6 Mar 2009)",
    ],
    leave_reply: function(){

    },
    feed: "http://feeds.feedburner.com/burcudogan",
    copyright: "Writings and the JS object literal template is by Burcu Dogan."
};