| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- // Author: Orlys
- // Github: https://github.com/Orlys
- namespace Yuuna.Contracts.Modules
- {
- using System;
- using System.Reflection;
- [AttributeUsage(AttributeTargets.Class)]
- public sealed class ModuleMetadataAttribute : Attribute, IModuleMetadata
- {
- public ModuleMetadataAttribute(string name)
- {
- this.Name = name;
- }
- public string Name { get; private set; }
- public string Author { get; set; }
- public string Url { get; set; }
- public string Description { get; set; }
- internal static IModuleMetadata GetMetadata(Type type)
- {
- var meta = type.GetCustomAttribute<ModuleMetadataAttribute>();
- if (meta is null)
- meta = new ModuleMetadataAttribute(type.Name);
- else if (string.IsNullOrWhiteSpace(meta.Name))
- meta.Name = type.Name;
- return meta;
- }
- }
- //public abstract class ModuleBase
- //{
- // private readonly PatternFactory _patternfactory;
- // /// <summary>
- // /// 中繼資料。
- // /// </summary>
- // public ModuleMetadataAttribute Metadata { get; }
- // internal IPatternSet Patterns => this._patternfactory;
- // public ModuleBase()
- // {
- // this.Status = ModuleStatus.Uninitialized;
- // this._patternfactory = new PatternFactory(this);
- // this.Metadata = ModuleMetadataAttribute.GetMetadata(this.GetType());
- // }
- // /// <summary>
- // /// 表示模組是否已初始化。
- // /// </summary>
- // public ModuleStatus Status { get; private set; }
- // /// <summary>
- // /// 初始化模組
- // /// </summary>
- // /// <param name="textSegmenter">分詞器</param>
- // /// <param name="groupManager">群組管理</param>
- // internal void Initialize(ITextSegmenter textSegmenter, IGroupManager groupManager)
- // {
- // if (this.Status.Equals(ModuleStatus.Uninitialized))
- // {
- // try
- // {
- // this.BuildPatterns(groupManager, this._patternfactory);
- // textSegmenter.Load(groupManager);
- // this.Status = ModuleStatus.Initialized;
- // this.AfterInitialize();
- // }
- // catch //(Exception e)
- // {
- // this.Status = ModuleStatus.FailToInitialize;
- // }
- // }
- // }
- // /// <summary>
- // /// 在初始化後引發。
- // /// </summary>
- // protected virtual void AfterInitialize()
- // {
- // }
- // /// <summary>
- // /// 建立模式規則。
- // /// </summary>
- // /// <param name="g"></param>
- // /// <param name="p"></param>
- // protected abstract void BuildPatterns(IGroupManager g, IPatternBuilder p);
- //}
- }
|