Paulo Morgado

.NET Development & Architecture

This Blog

Syndication

Search

Sponsored By

Tags

News

Unit Test Today! Get Typemock Isolator!

Books

 

Events

Visitors

Visitor Locations

Community

Email Notifications

Archives

Profile

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 Thu, May 24 2007 0:29 by Paulo Morgado

Comments

# re: My C# Naming Conventions For Partial Class Files@ Monday, June 18, 2007 7:20 AM

nested classes, right? ;)

Zygimantas Berziunas

# re: My C# Naming Conventions For Partial Class Files@ Monday, June 18, 2007 7:05 PM

Also, but not only.

Paulo Morgado

# C# Naming Conventions For Partial Class Files@ Wednesday, November 21, 2007 11:06 PM

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

DotNetKicks.com

# partial class [C# ASP.NET VS2005] « seeing things behind my glasses@ Sunday, June 01, 2008 10:00 AM

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

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

Leave a Comment

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