using System; using JD.Kernel.StaticHelpers; namespace JD.TeaBoxAddinSystem.Addins.Description { /// /// An is a path in the addin tree in which addins can place s. /// public sealed class ExtensionPoint : AddinObject, IExtensionTypeSetContainer { #region Variables private readonly string m_path; private readonly ExtensionTypeSet m_extensionTypeSet = new ExtensionTypeSet(); private string m_name = string.Empty; private string m_description = string.Empty; #endregion #region Constructor /// /// Constructor. /// /// public ExtensionPoint(string path) { Throw.IfEmpty(path, "path"); m_path = NormalizePath(path); } #endregion #region Properties /// /// Whether the extension point is deprecated /// public bool IsDeprecated { get { return !string.IsNullOrEmpty(DeprecationMessage); } } public string DeprecationMessage { get; set; } #region Path Separators /// /// Main Path Separator. /// public static readonly char PathSeparator = System.IO.Path.AltDirectorySeparatorChar; /// /// Valid path separators. /// private static readonly char[] m_pathSeparators = new char[] { System.IO.Path.AltDirectorySeparatorChar, System.IO.Path.DirectorySeparatorChar }; /// /// Returns the valid path separators. /// /// public static char[] GetPathSeparators() { return (char[])m_pathSeparators.Clone(); } #endregion /// /// Path of this extension point. /// public string Path { get { return m_path; } } /// /// The extension type set that is used for this extension point. /// public ExtensionTypeSet ExtensionTypeSet { get { return m_extensionTypeSet; } } /// /// Optional name of this extension point. /// public string Name { get { return m_name; } set { ThrowIfLoaded(); m_name = value; } } /// /// Optional description of this extension point. /// public string Description { get { return m_description; } set { ThrowIfLoaded(); m_description = value; } } #endregion #region Methods /// /// Overriden. /// /// internal override void OnModuleChanged(EventArgs e) { m_extensionTypeSet.Module = Module; base.OnModuleChanged(e); } internal static string NormalizePath(string path) { path = FileUtility.FormatPath(path); if (!string.IsNullOrEmpty(path) && path[0] == PathSeparator) { path = path.Remove(0, 1); } return path; } /// /// Overriden. /// /// public override string ToString() { return $"[ExtensionPoint: Path={Path}{(string.IsNullOrEmpty(Name) ? string.Empty : $", Name={Name}")}]"; } #endregion } }