12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- 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
- }
- }
|