ModuleMetadataAttribute.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Author: Orlys
  2. // Github: https://github.com/Orlys
  3. namespace Yuuna.Contracts.Modules
  4. {
  5. using System;
  6. using System.Reflection;
  7. [AttributeUsage(AttributeTargets.Class)]
  8. public sealed class ModuleMetadataAttribute : Attribute, IModuleMetadata
  9. {
  10. public ModuleMetadataAttribute(string name)
  11. {
  12. this.Name = name;
  13. }
  14. public string Name { get; private set; }
  15. public string Author { get; set; }
  16. public string Url { get; set; }
  17. public string Description { get; set; }
  18. internal static IModuleMetadata GetMetadata(Type type)
  19. {
  20. var meta = type.GetCustomAttribute<ModuleMetadataAttribute>();
  21. if (meta is null)
  22. meta = new ModuleMetadataAttribute(type.Name);
  23. else if (string.IsNullOrWhiteSpace(meta.Name))
  24. meta.Name = type.Name;
  25. return meta;
  26. }
  27. }
  28. //public abstract class ModuleBase
  29. //{
  30. // private readonly PatternFactory _patternfactory;
  31. // /// <summary>
  32. // /// 中繼資料。
  33. // /// </summary>
  34. // public ModuleMetadataAttribute Metadata { get; }
  35. // internal IPatternSet Patterns => this._patternfactory;
  36. // public ModuleBase()
  37. // {
  38. // this.Status = ModuleStatus.Uninitialized;
  39. // this._patternfactory = new PatternFactory(this);
  40. // this.Metadata = ModuleMetadataAttribute.GetMetadata(this.GetType());
  41. // }
  42. // /// <summary>
  43. // /// 表示模組是否已初始化。
  44. // /// </summary>
  45. // public ModuleStatus Status { get; private set; }
  46. // /// <summary>
  47. // /// 初始化模組
  48. // /// </summary>
  49. // /// <param name="textSegmenter">分詞器</param>
  50. // /// <param name="groupManager">群組管理</param>
  51. // internal void Initialize(ITextSegmenter textSegmenter, IGroupManager groupManager)
  52. // {
  53. // if (this.Status.Equals(ModuleStatus.Uninitialized))
  54. // {
  55. // try
  56. // {
  57. // this.BuildPatterns(groupManager, this._patternfactory);
  58. // textSegmenter.Load(groupManager);
  59. // this.Status = ModuleStatus.Initialized;
  60. // this.AfterInitialize();
  61. // }
  62. // catch //(Exception e)
  63. // {
  64. // this.Status = ModuleStatus.FailToInitialize;
  65. // }
  66. // }
  67. // }
  68. // /// <summary>
  69. // /// 在初始化後引發。
  70. // /// </summary>
  71. // protected virtual void AfterInitialize()
  72. // {
  73. // }
  74. // /// <summary>
  75. // /// 建立模式規則。
  76. // /// </summary>
  77. // /// <param name="g"></param>
  78. // /// <param name="p"></param>
  79. // protected abstract void BuildPatterns(IGroupManager g, IPatternBuilder p);
  80. //}
  81. }