1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- namespace Wayne.Lib.StateEngine
- {
- /// <summary>
- /// An attribute that can be applied to state classes, that is used to
- /// document the state.
- /// </summary>
- [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1036:OverrideMethodsOnComparableTypes")]
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments")]
- public sealed class StateDescriptionAttribute : Attribute, IComparable
- {
- #region Fields
- private StateDescriptionType descriptionType;
- private string description;
- #endregion
- #region Construction
- /// <summary>
- /// Creates a Summary state engine description for the class.
- /// </summary>
- /// <param name="description">Description.</param>
- public StateDescriptionAttribute(string description)
- : this(StateDescriptionType.Summary, description)
- {
- }
- /// <summary>
- /// Creates a state engine description for the class.
- /// </summary>
- /// <param name="descriptionType">Category for the description.</param>
- /// <param name="description">Description.</param>
- public StateDescriptionAttribute(StateDescriptionType descriptionType, string description)
- {
- this.descriptionType = descriptionType;
- this.description = description;
- }
- /// <summary>
- /// Creates a state engine description for the class.
- /// </summary>
- /// <param name="descriptionType">Category for the description.</param>
- /// <param name="type">Type that stands for the description.</param>
- public StateDescriptionAttribute(StateDescriptionType descriptionType, Type type)
- {
- if (type == null)
- throw new ArgumentNullException("type");
- this.descriptionType = descriptionType;
- this.description = type.FullName;
- }
- #endregion
- #region Properties
- /// <summary>
- /// The category of the description.
- /// </summary>
- public StateDescriptionType DescriptionType
- {
- get { return descriptionType; }
- }
- /// <summary>
- /// Description.
- /// </summary>
- public string Description
- {
- get { return description; }
- }
- #endregion
- #region IComparable Members
- /// <summary>
- /// Compares this attribute with another one.
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public int CompareTo(object obj)
- {
- StateDescriptionAttribute compareStateDescriptionAttribute = obj as StateDescriptionAttribute;
- if (compareStateDescriptionAttribute != null)
- return DescriptionType.CompareTo(compareStateDescriptionAttribute.DescriptionType);
- return 0;
- }
- #endregion
- }
- }
|