EventDescriptionAttribute.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #region --------------- Copyright Dresser Wayne Pignone -------------
  2. /*
  3. * $Log: /Wrk/WayneLibraries/Wrk/StateEngine/Description/EventDescriptionAttribute.cs $
  4. *
  5. * 2 08-02-26 14:13 Mattias.larsson
  6. * Not "sealed" anymore.
  7. */
  8. #endregion
  9. using System;
  10. namespace Wayne.Lib.StateEngine
  11. {
  12. /// <summary>
  13. /// Describe the event / transition relationship for a state class.
  14. /// </summary>
  15. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
  16. public class EventDescriptionAttribute : EnterDescriptionAttribute
  17. {
  18. #region Fields
  19. object eventType;
  20. #endregion
  21. #region Construction
  22. /// <summary>
  23. /// Describe an unconditional event / transition relationship for a state class.
  24. /// </summary>
  25. /// <param name="eventType">Event type object</param>
  26. /// <param name="transitionType">Transition that is performed.</param>
  27. public EventDescriptionAttribute(object eventType, object transitionType)
  28. : this(eventType, "", transitionType)
  29. {
  30. this.eventType = eventType;
  31. }
  32. /// <summary>
  33. /// Describe the event / transition relationship for a state class.
  34. /// </summary>
  35. /// <param name="eventType">Event type object</param>
  36. /// <param name="conditionText">A descriptive text for the condition.</param>
  37. /// <param name="transitionType">Transition that is performed.</param>
  38. public EventDescriptionAttribute(object eventType, string conditionText, object transitionType)
  39. : base(conditionText, transitionType)
  40. {
  41. this.eventType = eventType;
  42. }
  43. #endregion
  44. #region Properties
  45. /// <summary>
  46. /// Event type object.
  47. /// </summary>
  48. public object EventType
  49. {
  50. get { return eventType; }
  51. }
  52. #endregion
  53. #region IComparable Members
  54. /// <summary>
  55. /// Compares this attribute with another one.
  56. /// </summary>
  57. /// <param name="obj"></param>
  58. /// <returns></returns>
  59. public override int CompareTo(object obj)
  60. {
  61. int result = 0;
  62. EventDescriptionAttribute compareEventDescriptionAttribute = obj as EventDescriptionAttribute;
  63. if (compareEventDescriptionAttribute != null)
  64. {
  65. if ((EventType != null) && (compareEventDescriptionAttribute.EventType != null))
  66. {
  67. //result = EventType.GetType().FullName.CompareTo(compareEventDescriptionAttribute.EventType.GetType().FullName);
  68. //if (result == 0)
  69. {
  70. result = EventType.ToString().CompareTo(compareEventDescriptionAttribute.EventType.ToString());
  71. if (result == 0)
  72. result = base.CompareTo(obj);
  73. }
  74. }
  75. else if (EventType != null)
  76. result = 1;
  77. else if (compareEventDescriptionAttribute.EventType != null)
  78. result = -1;
  79. }
  80. else
  81. {
  82. EnterDescriptionAttribute compareEnterDescriptionAttribute = obj as EnterDescriptionAttribute;
  83. if (compareEnterDescriptionAttribute != null)
  84. {
  85. // An EnterDescriptionAttribute should come before an EventDescriptionAttribute.
  86. return 1;
  87. }
  88. }
  89. return result;
  90. }
  91. #endregion
  92. }
  93. }