March 10, 2006

Partial classes in .NET 2.0

The partial attribute refers to partial classes, a new concept in the .NET Framework 2.0. A partial class is a class whose definition may spread over distinct source files. Each source file appears to contain an ordinary class definition from beginning to end, except that it is partial and doesn't exhaust the logic required by the class. The compiler will merge partial class definitions into a complete definition of the class that can be compiled. Partial classes have nothing to do with object-orientation; they are a source-level and assembly-limited way to extend the behavior of a class within a project. In the .NET Framework 2.0, partial classes are the means used to prevent Visual Studio 2005 from injecting auto-generated code inside code files. Any binding code that is missing in the original class will be added by the runtime, through the addition of a partial class.