I don't really use this feature often,
but I quite like the concept of partial classes. It's one of those things that
might not be very interesting technically, but it can be very handy.
Typically you will use partial
classes to separate parts of a class that are automatically generated from
those that are manually added/edited so that you can keep auto-generating
without worrying about losing your manual work. I am currently working on a
"proof of concept" project and I wanted to demonstrate how a
specific class would look like when the final solution would be implemented. We
are interested in the complexity of this class (we want it as small and as
simple as possible), so I used a partial class to "hide" the parts of
the class that would not be there in the final solution (some will be
auto-generated and some will become part of the framework it sits in). It's
much better to be able to show somebody that it will be simple and short rather
than say "trust me, when we do this properly it will be better".
Anyway, as I was happily splitting
my class up into two different files I realised that I am not sure what to name
the second file. I mean, the rule is that the file name needs to be the same
name as the class. That's the rule. You can't break the rule. You break the
rule, the whole world falls apart. But I had to break the rule, I couldn't have
the same name for more than one file. Needless to say, I was panicking. Then I
thought maybe I don't have to break the rule, maybe I can just come up with a
new rule that takes into consideration partial classes and the world wouldn't
have to fall apart.
I had a quick look online for some best
practices, naming conventions, etc. online but nothing really covers partial
classes. The only example of them that I have is the way Visual Studio uses
them for Windows Forms. The main file is called "ClassName.cs" and
the second (auto-generated) file is called "ClassName.Designer.cs". I
think I quite like this
lets-confuse-arcaine-applications-by-using-two-dots-in-the-filename approach. The
first bit can be the name of the class and the second bit can be the
reason the class is split into two.