// 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(); 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; // /// // /// 中繼資料。 // /// // 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()); // } // /// // /// 表示模組是否已初始化。 // /// // public ModuleStatus Status { get; private set; } // /// // /// 初始化模組 // /// // /// 分詞器 // /// 群組管理 // 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; // } // } // } // /// // /// 在初始化後引發。 // /// // protected virtual void AfterInitialize() // { // } // /// // /// 建立模式規則。 // /// // /// // /// // protected abstract void BuildPatterns(IGroupManager g, IPatternBuilder p); //} }