166 lines
4 KiB
C#
166 lines
4 KiB
C#
using System;
|
|
using JD.Kernel.StaticHelpers;
|
|
|
|
namespace JD.TeaBoxAddinSystem.Addins.Description
|
|
{
|
|
/// <summary>
|
|
/// An <see cref="ExtensionPoint"/> is a path in the addin tree in which addins can place <see cref="ExtensionNode"/>s.
|
|
/// </summary>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
public ExtensionPoint(string path)
|
|
{
|
|
Throw.IfEmpty(path, "path");
|
|
m_path = NormalizePath(path);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Whether the extension point is deprecated
|
|
/// </summary>
|
|
public bool IsDeprecated
|
|
{
|
|
get { return !string.IsNullOrEmpty(DeprecationMessage); }
|
|
}
|
|
|
|
public string DeprecationMessage
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
|
|
#region Path Separators
|
|
|
|
/// <summary>
|
|
/// Main Path Separator.
|
|
/// </summary>
|
|
public static readonly char PathSeparator = System.IO.Path.AltDirectorySeparatorChar;
|
|
|
|
/// <summary>
|
|
/// Valid path separators.
|
|
/// </summary>
|
|
private static readonly char[] m_pathSeparators = new char[] { System.IO.Path.AltDirectorySeparatorChar, System.IO.Path.DirectorySeparatorChar };
|
|
|
|
/// <summary>
|
|
/// Returns the valid path separators.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static char[] GetPathSeparators()
|
|
{
|
|
return (char[])m_pathSeparators.Clone();
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Path of this extension point.
|
|
/// </summary>
|
|
public string Path
|
|
{
|
|
get
|
|
{
|
|
return m_path;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The extension type set that is used for this extension point.
|
|
/// </summary>
|
|
public ExtensionTypeSet ExtensionTypeSet
|
|
{
|
|
get
|
|
{
|
|
return m_extensionTypeSet;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Optional name of this extension point.
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return m_name;
|
|
}
|
|
set
|
|
{
|
|
ThrowIfLoaded();
|
|
m_name = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Optional description of this extension point.
|
|
/// </summary>
|
|
public string Description
|
|
{
|
|
get
|
|
{
|
|
return m_description;
|
|
}
|
|
set
|
|
{
|
|
ThrowIfLoaded();
|
|
m_description = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Overriden.
|
|
/// </summary>
|
|
/// <param name="e"></param>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Overriden.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return $"[ExtensionPoint: Path={Path}{(string.IsNullOrEmpty(Name) ? string.Empty : $", Name={Name}")}]";
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|