You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  1. using Apewer.Internals;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. using System.Text;
  6. namespace Apewer
  7. {
  8. /// <summary></summary>
  9. [Serializable]
  10. [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)]
  11. public class CaptionAttribute : Attribute
  12. {
  13. private string _title, _description, _remark;
  14. /// <summary></summary>
  15. public CaptionAttribute(string title = null, string description = null, string remark = null)
  16. {
  17. Title = title;
  18. Description = description;
  19. Remark = remark;
  20. }
  21. /// <summary></summary>
  22. public string Title
  23. {
  24. get { return _title; }
  25. set { _title = value ?? Constant.EmptyString; }
  26. }
  27. /// <summary></summary>
  28. public string Description
  29. {
  30. get { return _description; }
  31. set { _description = value ?? Constant.EmptyString; }
  32. }
  33. /// <summary></summary>
  34. public string Remark
  35. {
  36. get { return _remark; }
  37. set { _remark = value ?? Constant.EmptyString; }
  38. }
  39. /// <summary></summary>
  40. public static string GetTitle(MethodInfo method, bool inherit = true)
  41. {
  42. if (method == null) return null;
  43. var attributes = method.GetCustomAttributes(typeof(CaptionAttribute), inherit);
  44. if (attributes.Length > 0)
  45. {
  46. var attribute = attributes[0] as CaptionAttribute;
  47. return attribute.Title;
  48. }
  49. return method.Name;
  50. }
  51. }
  52. }