tags:

views:

234

answers:

7

I have a c# enumeration that looks like this:

public enum EthernetLinkSpeed {

    [Description("10BASE-T")]
    _10BaseT,

    [Description("100BASE-T")]
    _100BaseT,

    [Description("1000BASE-T")]
    _1000BaseT,

    [Description("Disconnected")]
    Disconnected
}

I added a leading underscore to each value to make the compiler happy.

Is there a standard naming convention for enumerations like this? The underscore I've used doesn't seem like the best choice.

+11  A: 

I know of no convention, but how about

public enum EthernetLinkSpeed {
 Link10BaseT, Link1000BaseT, LinkDisconnected
}
CVertex
+1 In C and in linux, serial port enumerations use this kind of prefix (sometimes shorter): Baud rates are named Bxxxxx where xxxxx is the (integer constant) speed: B9600 is a 9600 baud rate. Anyway, the idea is the same: a short prefix that helps identify the content.
David Rodríguez - dribeas
I selected this suggestion as the answer for my particular example, however the general consensus seems to be that a standard prefix of some sort is necessary.
+1  A: 

I'm not sure if there is a convention, but something like this may be subjectively less 'ugly':

public enum EthernetLinkSpeed {

    [Description("10BASE-T")]
    TenBaseT,

    [Description("100BASE-T")]
    OneHundredBaseT,

    [Description("1000BASE-T")]
    OneThousandBaseT,

    [Description("Disconnected")]
    Disconnected
}
Dan Diplo
+4  A: 

I just look for something more descriptive in this case. For instance, since you have a "Disconnected" enum value, I would use something like:

public enum EthernetLinkSpeed {
    Connected10BaseT,
    Connected100BaseT,
    Connected1000BaseT,
    Disconnected
}

Since these are compile-time only, there's no damage in having them as long you like, even if making them long just means making them descriptive enough to pass the compiler's naming rules.

JoshJordan
+2  A: 

Not a direct answer, but the built-in NetworkInterfaceType enum includes the following values:

Ethernet, Ethernet3Megabit, FastEthernetT, FastEthernetFx, GigabitEthernet

It's a bit ugly for my liking, but I might consider using an Ethernet prefix for your enum:

public enum EthernetLinkSpeed
{
    [Description("10BASE-T")]
    Ethernet10BaseT,

    [Description("100BASE-T")]
    Ethernet100BaseT,

    [Description("1000BASE-T")]
    Ethernet1000BaseT,

    [Description("Disconnected")]
    Disconnected
}
LukeH
Definitely not the naming I would choose...
rstevens
A: 

As you've noticed, names are important. So, sometimes it's good to explore non-obvious alternatives.

A completely different alternative:

public enum EthernetLinkSpeed {

  [Description("10BASE-T")]
  MegabitSlow,

  [Description("100BASE-T")]
  MegabitFast,

  [Description("1000BASE-T")]
  Gigabit,

  [Description("Disconnected")]
  Disconnected
}
John Fisher
+1  A: 

We usually prefix them with 'e'

public enum EthernetLinkSpeed
{
    e10BaseT,
    e100BaseT,
    e1000BaseT,
    Disconnected
}

We deal with a lot of video resolutions, 720p etc, so we use e720p. In your case, I think using the names may be better, Ethernet, FastEthernet, and GigabitEthernet.

Brandon
A: 

It never hurts to add a unique prefix to all the related enums. If nothing else, it helps with search/replace editing of your source code down the road.

Loadmaster