using System; using System.Collections.Generic; using System.Text; namespace Wayne.Lib.StateEngine { /// /// Add a keyword to the state. Group the keywords in categories. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1036:OverrideMethodsOnComparableTypes")] public sealed class KeywordDescriptionAttribute : Attribute, IComparable { #region Fields private object category; private object keyword; private string description; #endregion #region Construction /// /// Add a keyword to the state. Group the keywords in categories. /// /// Category that the keyword belongs to. /// Keyword that should be associated with the state. /// Descriptive text. public KeywordDescriptionAttribute(object category, object keyword, string description) { this.category = category; this.keyword = keyword; this.description = description; } /// /// Add a keyword to the state. Group the keywords in categories. /// /// Category that the keyword belongs to. /// Keyword that should be associated with the state. public KeywordDescriptionAttribute(object category, object keyword) : this(category, keyword, "") { } #endregion #region Properties /// /// Category that the keyword belongs to. /// public object Category { get { return category; } } /// /// Keyword that should be associated with the state. /// public object Keyword { get { return keyword; } } /// /// Keyword as a string. /// public string KeywordText { get { Type keywordAsType = keyword as Type; if (keywordAsType != null) return keywordAsType.FullName; return keyword.ToString(); } } /// /// Descriptive text. /// public string Description { get { return description; } } #endregion #region IComparable Members /// /// Compares this attribute with another one. /// /// /// public int CompareTo(object obj) { int result = 0; KeywordDescriptionAttribute compareKeywordDescriptionAttribute = obj as KeywordDescriptionAttribute; if (compareKeywordDescriptionAttribute != null) { result = category.ToString().CompareTo(compareKeywordDescriptionAttribute.category.ToString()); if (result == 0) result = KeywordText.CompareTo(compareKeywordDescriptionAttribute.KeywordText); } return result; } #endregion } }