StateDescriptionAttribute.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. namespace Wayne.Lib.StateEngine
  3. {
  4. /// <summary>
  5. /// An attribute that can be applied to state classes, that is used to
  6. /// document the state.
  7. /// </summary>
  8. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
  9. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1036:OverrideMethodsOnComparableTypes")]
  10. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments")]
  11. public sealed class StateDescriptionAttribute : Attribute, IComparable
  12. {
  13. #region Fields
  14. private StateDescriptionType descriptionType;
  15. private string description;
  16. #endregion
  17. #region Construction
  18. /// <summary>
  19. /// Creates a Summary state engine description for the class.
  20. /// </summary>
  21. /// <param name="description">Description.</param>
  22. public StateDescriptionAttribute(string description)
  23. : this(StateDescriptionType.Summary, description)
  24. {
  25. }
  26. /// <summary>
  27. /// Creates a state engine description for the class.
  28. /// </summary>
  29. /// <param name="descriptionType">Category for the description.</param>
  30. /// <param name="description">Description.</param>
  31. public StateDescriptionAttribute(StateDescriptionType descriptionType, string description)
  32. {
  33. this.descriptionType = descriptionType;
  34. this.description = description;
  35. }
  36. /// <summary>
  37. /// Creates a state engine description for the class.
  38. /// </summary>
  39. /// <param name="descriptionType">Category for the description.</param>
  40. /// <param name="type">Type that stands for the description.</param>
  41. public StateDescriptionAttribute(StateDescriptionType descriptionType, Type type)
  42. {
  43. if (type == null)
  44. throw new ArgumentNullException("type");
  45. this.descriptionType = descriptionType;
  46. this.description = type.FullName;
  47. }
  48. #endregion
  49. #region Properties
  50. /// <summary>
  51. /// The category of the description.
  52. /// </summary>
  53. public StateDescriptionType DescriptionType
  54. {
  55. get { return descriptionType; }
  56. }
  57. /// <summary>
  58. /// Description.
  59. /// </summary>
  60. public string Description
  61. {
  62. get { return description; }
  63. }
  64. #endregion
  65. #region IComparable Members
  66. /// <summary>
  67. /// Compares this attribute with another one.
  68. /// </summary>
  69. /// <param name="obj"></param>
  70. /// <returns></returns>
  71. public int CompareTo(object obj)
  72. {
  73. StateDescriptionAttribute compareStateDescriptionAttribute = obj as StateDescriptionAttribute;
  74. if (compareStateDescriptionAttribute != null)
  75. return DescriptionType.CompareTo(compareStateDescriptionAttribute.DescriptionType);
  76. return 0;
  77. }
  78. #endregion
  79. }
  80. }