Cook Computing

Class Augmentation

August 20, 2002 Written by Charles Cook

I'm working on a project in which the use of nested classes within a single parent class makes for a very large source file. I'd like to be able to spread the parent class across several source files, one for each of the nested classes. Unfortunately C# does not support class augmentation (as this capability is called in chapter six of Inside Microsoft .NET IL Assembler). Once a class declaration in C# has been closed it cannot be re-opened. For example the following is not allowed:


class A
{
  public void Foo() { }
}

class A
{
  public void Bar() { }
}

Class augmentation is supported by ILAsm and would look something like this:


.class A
{
  .method public void Foo()
  {
    ret
  }
}
// following possibly in another source file
.class A
{
  .method public void Bar()
  {
    ret
  }
}