Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm asking this question despite having read similar but not exactly what I want at C# naming convention for enum and matching property

I found I have a tendency to name enums in plural and then 'use' them as singular, example:

public enum EntityTypes {
  Type1, Type2
}

public class SomeClass {
  /*
    some codes
  */

  public EntityTypes EntityType {get; set;}

}

Of course it works and this is my style, but can anyone find potential problem with such convention? I do have an "ugly" naming with the word "Status" though:

public enum OrderStatuses {
  Pending, Fulfilled, Error, Blah, Blah
}

public class SomeClass {
  /*
    some codes
  */

  public OrderStatuses OrderStatus {get; set;}

}

Additional Info: Maybe my question wasn't clear enough. I often have to think hard when naming the variables of the my defined enum types. I know the best practice, but it doesn't help to ease my job of naming those variables.

I can't possibly expose all my enum properties (say "Status") as "MyStatus".

My question: Can anyone find potential problem with my convention described above? It is NOT about best practice.

Question rephrase:

Well, I guess I should ask the question this way: Can someone come out a good generic way of naming the enum type such that when used, the naming of the enum 'instance' will be pretty straightforward?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
859 views
Welcome To Ask or Share your Answers For Others

1 Answer

Microsoft recommends using singular for Enums unless the Enum represents bit fields (use the FlagsAttribute as well). See Enumeration Type Naming Conventions (a subset of Microsoft's Naming Guidelines).

To respond to your clarification, I see nothing wrong with either of the following:

public enum OrderStatus { Pending, Fulfilled, Error };

public class SomeClass { 
    public OrderStatus OrderStatus { get; set; }
}

or

public enum OrderStatus { Pending, Fulfilled, Error };

public class SomeClass {
    public OrderStatus Status { get; set; }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...