123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using System;
- namespace Wayne.Lib.StateEngine
- {
- /// <summary>
- /// Add a keyword to the state. Group the keywords in categories.
- /// </summary>
- [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
- /// <summary>
- /// Add a keyword to the state. Group the keywords in categories.
- /// </summary>
- /// <param name="category">Category that the keyword belongs to.</param>
- /// <param name="keyword">Keyword that should be associated with the state.</param>
- /// <param name="description">Descriptive text.</param>
- public KeywordDescriptionAttribute(object category, object keyword, string description)
- {
- this.category = category;
- this.keyword = keyword;
- this.description = description;
- }
- /// <summary>
- /// Add a keyword to the state. Group the keywords in categories.
- /// </summary>
- /// <param name="category">Category that the keyword belongs to.</param>
- /// <param name="keyword">Keyword that should be associated with the state.</param>
- public KeywordDescriptionAttribute(object category, object keyword)
- : this(category, keyword, "")
- {
- }
- #endregion
- #region Properties
- /// <summary>
- /// Category that the keyword belongs to.
- /// </summary>
- public object Category
- {
- get { return category; }
- }
- /// <summary>
- /// Keyword that should be associated with the state.
- /// </summary>
- public object Keyword
- {
- get { return keyword; }
- }
- /// <summary>
- /// Keyword as a string.
- /// </summary>
- public string KeywordText
- {
- get
- {
- Type keywordAsType = keyword as Type;
- if (keywordAsType != null)
- return keywordAsType.FullName;
- return keyword.ToString();
- }
- }
- /// <summary>
- /// Descriptive text.
- /// </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)
- {
- 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
- }
- }
|