using System; using System.Collections.Generic; using System.Text; namespace Wayne.Lib.StateEngine { /// /// An attribute that can be applied to state classes, that is used to /// document the state. /// [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 /// /// Creates a Summary state engine description for the class. /// /// Description. public StateDescriptionAttribute(string description) : this(StateDescriptionType.Summary, description) { } /// /// Creates a state engine description for the class. /// /// Category for the description. /// Description. public StateDescriptionAttribute(StateDescriptionType descriptionType, string description) { this.descriptionType = descriptionType; this.description = description; } /// /// Creates a state engine description for the class. /// /// Category for the description. /// Type that stands for the description. public StateDescriptionAttribute(StateDescriptionType descriptionType, Type type) { if (type == null) throw new ArgumentNullException("type"); this.descriptionType = descriptionType; this.description = type.FullName; } #endregion #region Properties /// /// The category of the description. /// public StateDescriptionType DescriptionType { get { return descriptionType; } } /// /// Description. /// public string Description { get { return description; } } #endregion #region IComparable Members /// /// Compares this attribute with another one. /// /// /// public int CompareTo(object obj) { StateDescriptionAttribute compareStateDescriptionAttribute = obj as StateDescriptionAttribute; if (compareStateDescriptionAttribute != null) return DescriptionType.CompareTo(compareStateDescriptionAttribute.DescriptionType); return 0; } #endregion } }