I lot of times in our Business Object Model we use enums, these enum property could be a string, integer or a short value. While retrieving records from the database we need to set the property in the BOM to that of the enum value.

Here is one of those methods that you can never find when you're looking for it

   1: // suppose we have a enum
   2: enum PublishingStatus : short
   3: {
   4:     Draft = 1,
   5:     PendingApproval = 2,
   6:     Active = 3,
   7:     Archived = 4,
   8:     PendingDeletion = 5
   9: }
  10:  
  11: //set a default value
  12: PublishingStatusEnum CurrentPublishingStatus = PublishingStatusEnum.Draft;
  13: if (Enum.IsDefined(typeof(PublishingStatusEnum), Helper.GetShort(Reader["CurrentPublishingStatusId"])))
  14:     CurrentPublishingStatus = (PublishingStatusEnum)Enum.Parse(typeof(PublishingStatusEnum), Reader["CurrentPublishingStatusId"].ToString());
  15:  
  16: // suppose we have a string enum
  17: enum SiteColors
  18: {
  19:     Red,
  20:     Blue,
  21:     Orange
  22: }
  23:  
  24: //set a default value
  25: SiteColors SelectedColor = SiteColors.Red;
  26: if (Enum.IsDefined(typeof(SiteColors), Reader["SiteColor"].ToString()))
  27:     SelectedColor = (SiteColors)Enum.Parse(typeof(SiteColors), Reader["SiteColor"].ToString(),true);
  28: // we passed the last variable as true of ignoreCase