CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Enum extension methods

728 Views
Copy Code Show/Hide Line Numbers
   1:  public static class EnumExtensions
   2:  {
   3:      public static T Append<T>(this Enum current, T flag)
   4:      {
   5:          return (T)Enum.ToObject(typeof(T), Convert.ToInt32(current) | Convert.ToInt32(flag));
   6:      }
   7:   
   8:      public static T Append<T>(this Enum current, bool condition, T flag)
   9:      {
  10:          var value = condition ?
  11:              Convert.ToInt32(current) | Convert.ToInt32(flag) : Convert.ToInt32(current);
  12:   
  13:          return (T)Enum.ToObject(typeof(T), value);
  14:      }
  15:  }
by TheCodeJunkie
  October 10, 2009 @ 2:42pm

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate