While I dug into Orcas March CTP Documentation I found another new C# feature (at least for me). It is called Partial Method Definitions and allows you to separate method definition and method implementation in partial classes.
//Definition
partial void partial void onNameChanged();
//Implementation
partial void onNameChanged()
{
//method body
}
As I have C++ background this sounds familiar to me and reminded me times when I had to declare methods in .h (header) files and put implementation in .c/.cpp files.
To be honest I am not able to find the advantages of this new feature but I suppose there will be more blog post soon that will discuss this.
As I emphasize above you can separate method definition from implementation only in partial classes. There are number of restrictions stated in Orcas documentation:
-
Partial method declarations must begin with the contextual keyword partial and the method must return void.
-
Partial methods can have ref but not out parameters.
-
Partial methods are implicitly private, and therefore they cannot be virtual.
-
Partial methods cannot be extern, because the presence of the body determines whether they are defining or implementing.
-
Partial methods can have static and unsafe modifiers.
-
Partial methods can be generic. Constraints are placed on the defining partial method declaration, and may optionally be repeated on the implementing one. Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one.
-
You can not make a delegate to a partial method.