title: how to use flags attribute with class inherit from enumeration
body: <p>How to implement multiple selections in a class which inherit from <code>Enumeration</code> With restrictions ?</p>
  
  <p>If I have five schedule types:</p>
  
  <ul>
  <li>Fixed schedule</li>
  <li>Rotated schedule</li>
  <li>FullTime schedule</li>
  <li>PartTime schedule</li>
  <li>Flexible schedule</li>
  </ul>
  
  <p>The first two options are versus <code>(Fixed vs Rotated)</code> and the second Two options <code>(FullTime  vs PartTime)</code> are versus, I mean the schedule can't be <code>fixed</code> and <code>rotated</code> at the same time or <code>fulltime and parttime</code> at the same time. but It may be <code>Fixed and FullTime</code> for example.</p>
  
  <hr>
  
  <p>Fixed work schedules which consists of the same number of hours and days worked per week and tend to stay consistent once the number of hours and days have been agreed upon by both the employer and the worker. </p>
  
  <p>Flexible work schedules in which employees and employers work together to determine the number of hours and days of the week they are able to commit to. 
  Full time work schedule which often require a commitment of 37 - 40 hours per week. Because of the long hours, careers with full time schedules are eligible for work benefits. These benefits can include leave, vacation and sickness, health insurance, and different retirement plan options.</p>
  
  <p>Part time work schedule which is any schedule less than full time employment.</p>
  
  <p>Rotating work schedule which cycle employees through day or week, swing, and night shifts. This cycle helps to distribute different shifts between all employees so that no one is stuck with just the less desirable hours.</p>
  
  <p>So I did the following:</p>
  
  <pre><code>public class Schedule
  {
      public Schedule()
      {
  
      }
  
      private ICollection&lt;ScheduleDetail&gt; _assignedWeeks;
      public int Id { get; set; }
      public string Name { get; set; }
      public int WorkingGroupId { get; set; }
      public ScheduleType ScheduleType { get; set; }
      public bool IsFixed { get; }
      public bool IsFlexible { get; }
      public bool IsFullTime { get; }
      public ICollection&lt;ScheduleDetail&gt; AssignedWeeks { get =&gt; _assignedWeeks; set =&gt; _assignedWeeks = value; }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public abstract class ScheduleType : Enumeration
      {
          protected ScheduleType(int value, string displayName) : base(value, displayName)
          {
          }
          public static readonly ScheduleType Fixed
         = new FixedType();
          public static readonly ScheduleType Flexible
              = new FlexibleType();
          public static readonly ScheduleType FullTime
              = new FullTimeType();
          public static readonly ScheduleType PartTime
             = new PartTimeType();
          public static readonly ScheduleType Rotated
             = new RotatedType();
  
  
  
          private class FixedType : ScheduleType
          {
              public FixedType() : base(1, "Fixed Work Schedule")
              {
              }
          }
  
          private class FlexibleType : ScheduleType
          {
              public FlexibleType() : base(2, "Flexible Work Schedule")
              {
              }
          }
  
          private class FullTimeType : ScheduleType
          {
              public FullTimeType() : base(3, "Full Time Work Schedule")
              {
              }
          }
  
          private class PartTimeType : ScheduleType
          {
              public PartTimeType() : base(4, "Part Time Work Schedule")
              {
              }
          }
          private class RotatedType : ScheduleType
          {
              public RotatedType() : base(5, "Rotated Work Schedule")
              {
              }
          }
      }
  </code></pre>
  
  <hr>
  
  <pre><code>public abstract class Enumeration : IComparable
      {
          private readonly int _value;
          private readonly string _displayName;
  
          protected Enumeration()
          {
          }
  
          protected Enumeration(int value, string displayName)
          {
              _value = value;
              _displayName = displayName;
          }
  
          public int Value
          {
              get { return _value; }
          }
  
          public string DisplayName
          {
              get { return _displayName; }
          }
  
          public override string ToString()
          {
              return DisplayName;
          }
  
          public static IEnumerable&lt;T&gt; GetAll&lt;T&gt;() where T : Enumeration, new()
          {
              var type = typeof(T);
              var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
  
              foreach (var info in fields)
              {
                  var instance = new T();
                  var locatedValue = info.GetValue(instance) as T;
  
                  if (locatedValue != null)
                  {
                      yield return locatedValue;
                  }
              }
          }
  
          public override bool Equals(object obj)
          {
              var otherValue = obj as Enumeration;
  
              if (otherValue == null)
              {
                  return false;
              }
  
              var typeMatches = GetType().Equals(obj.GetType());
              var valueMatches = _value.Equals(otherValue.Value);
  
              return typeMatches &amp;&amp; valueMatches;
          }
  
          public override int GetHashCode()
          {
              return _value.GetHashCode();
          }
  
          public static int AbsoluteDifference(Enumeration firstValue, Enumeration secondValue)
          {
              var absoluteDifference = Math.Abs(firstValue.Value - secondValue.Value);
              return absoluteDifference;
          }
  
          public static T FromValue&lt;T&gt;(int value) where T : Enumeration, new()
          {
              var matchingItem = parse&lt;T, int&gt;(value, "value", item =&gt; item.Value == value);
              return matchingItem;
          }
  
          public static T FromDisplayName&lt;T&gt;(string displayName) where T : Enumeration, new()
          {
              var matchingItem = parse&lt;T, string&gt;(displayName, "display name", item =&gt; item.DisplayName == displayName);
              return matchingItem;
          }
  
          private static T parse&lt;T, K&gt;(K value, string description, Func&lt;T, bool&gt; predicate) where T : Enumeration, new()
          {
              var matchingItem = GetAll&lt;T&gt;().FirstOrDefault(predicate);
  
              if (matchingItem == null)
              {
                  var message = string.Format("'{0}' is not a valid {1} in {2}", value, description, typeof(T));
                  throw new ApplicationException(message);
              }
  
              return matchingItem;
          }
  
          public int CompareTo(object other)
          {
              return Value.CompareTo(((Enumeration)other).Value);
          }
      }
  </code></pre>
  
  <hr>
  
  <p>So based on the user selection for a specific option or set of options, I have to call a method to set flags <code>(IsFixed,...)</code> in the Schedule class to control the the scheduledetails class in (Fixed and rotated) and the number of hours for(full time and part time)</p>
  
  <hr>
  
  <p>I'll be grateful for any suggestions or recommendations ?</p>