code_junkie

Next or previous enum

Nov 13th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. public enum TimeframeType {
  2. None = 0,
  3. [Description("1 month")]
  4. Now = 30,
  5. [Description("1-3 months")]
  6. Short = 90,
  7. [Description("3-6 months")]
  8. Medium = 180,
  9. [Description("6+ months")]
  10. Long = 360
  11. }
  12.  
  13. public static T EnumNext<T>(T value) where T : struct {
  14. T[] values = (T[])Enum.GetValues(typeof(T));
  15.  
  16. int i;
  17. for (i = 0; i < values.Length; i++) {
  18. if (object.Equals(value, values[i])) {
  19. break;
  20. }
  21. }
  22. if (i >= values.Length - 1) {
  23. return values[values.Length - 1];
  24. } else {
  25. return values[i + 1];
  26. }
  27. }
  28.  
  29. public class TimeFrame: IComparable
  30. {
  31. private int days;
  32.  
  33. public int Days
  34. {
  35. set
  36. {
  37. days = value;
  38. }
  39. }
  40.  
  41. public int CompareTo(object other)
  42. {
  43. //see this for implementation -- http://msdn.microsoft.com/en-us/library/system.icomparable.aspx#Mtps_DropDownFilterText
  44. }
  45.  
  46.  
  47. public string Description
  48. {
  49. get code to return the description string , ie "1-3 months"
  50. }
  51.  
  52. }
  53.  
  54. public enum TimeframeType {
  55. None = 0,
  56. [Description("1 month")]
  57.  
  58. TimeFrameStep = 30,
  59. [Description("Step from previous to next")]
  60.  
  61. Now = None + TimeFrameStep,
  62. [Description("1-3 months")]
  63.  
  64. Short = Now + TimeFrameStep,
  65. [Description("3-6 months")]
  66.  
  67. Medium = Now + TimeFrameStep,
  68. [Description("6+ months")]
  69.  
  70. Long = Medium + TimeFrameStep,
  71. [Description("12 months")]
  72. }
Add Comment
Please, Sign In to add comment