StateDescriptionAttribute.cs 3.1 KB

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