Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com
Property Naming Guidelines recommends to consider creating a property with the same name as its underlying type. For example, if you declare a property named Color, the type of the property should likewise be Color.
Enumeration Type Naming Guidelines recommends  do not use an Enum suffix on Enum type names.
 
I found this recommendation conflicting if I want to declare Enum within class and have a property of the type of this enum.
I've tried to create something like the following:.
 
public class Control
{
   public enum Color
  {
   // Insert code for Enum here.
  }

   public Color Color //confusing
   {
      get {// Insert code here.}
      set {// Insert code here.}

}

}

This doesnt't work well, because compiler confused, do you refer to the Enum or Property. It probably will work if you will refer to enum with fully qualified namespace.
It also will work, if enum Color will be declared outside the class(as in
MSDN example), but I don't want to do it, because my enum is logically belongs to my class.

The possible alternative is to ignore recommendation  do not use an Enum suffix

public class Control
{
   public enum ColorEnum // not recommended
  {
   // Insert code for Enum here.
  }

   public ColorEnum  Color 
   {
      get {// Insert code here.}
      set {// Insert code here.}

}

}

The best way is to use the name of the property derivative but different to enum.
If you have too many members in the class, consider to add an extra word as the suffix, not prefix- to help find the property in IntelliSence. For example,
ColorSelected will be easier to find, than SelectedColor

public class Control
{

   public enum Color
  {
   // Insert code for Enum here.
  }

   public Color ColorCurrent //or ColorSelected or ColorMyFavorite
   {
      get {// Insert code here.}
      set {// Insert code here.}

}

}

Posted on Tuesday, May 27, 2008 12:52 AM .Net Framework | Back to top


Comments on this post: Naming Guidelines: Names for embedded Enum and Property of the enum type

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net