My C# Naming Conventions For Partial Class Files

Following up on a previous post, this time I'll give you my naming conventions for partial class files.

There are two main reasons for me to break a class definition into more than one file. The main one is when I have inner classes and the other is when the file is getting too big.

How should I name the files? The usual tendency is to use a “.” as separator. This looks nice until you came across something like this:

public class MyComponent

{

    private class Activation

    {

        // Class implementation.

    }

 

    private class Deployment

    {

        // Class implementation.

    }

 

    #region Event Handling

 

    // Event handling code.

 

    #endregion

}

If I would extract the inner classes and use the “.” as separator, I would end up with the following list of files:

  • MyComponent.Activation.cs
  • MyComponent.cs
  • MyComponent.Deployment.cs

And, what about the long event handling code? Should I do the same? If so, I will end up with the following list of files:

  • MyComponent.Activation.cs
  • MyComponent.cs
  • MyComponent.Deployment.cs
  • MyComponent.EventHandling.cs

This doesn’t look very nice, does it?

So, here is my proposal:

  • “-“ separator for code from the top class
  • “+” separator for inner classes

This way, I end up with the following list of files:

  • MyComponent.cs
  • MyComponent-EventHandling.cs
  • MyComponent+Activation.cs
  • MyComponent+Deployment.cs

And this looks a lot nicer.

Published Thursday, May 24, 2007 12:29 AM by Paulo Morgado

Comments

Monday, June 18, 2007 7:20 AM by Zygimantas Berziunas

# re: My C# Naming Conventions For Partial Class Files

nested classes, right? ;)

Monday, June 18, 2007 7:05 PM by Paulo Morgado

# re: My C# Naming Conventions For Partial Class Files

Also, but not only.

Wednesday, November 21, 2007 11:06 PM by DotNetKicks.com

# C# Naming Conventions For Partial Class Files

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# partial class [C# ASP.NET VS2005] « seeing things behind my glasses

Pingback from  partial class [C# ASP.NET VS2005] « seeing things behind my glasses

Leave a Comment

(required) 
(required) 
(optional)
(required)