JD2022-TU1/main/tools/framework/JD.TeaBoxAddinSystem/Addins/Implementation.cs

50 lines
1.3 KiB
C#

using System.Collections.Generic;
using System.Drawing;
using JD.TeaBoxAddinSystem.Addins.Internal;
namespace JD.TeaBoxAddinSystem.Addins
{
/// <summary>
/// Separate the implementation from the current manager to let tests mock the addins tree.
/// </summary>
public class Implementation
{
public virtual IList<T> GetExtensionObjects<T>(string path)
{
ExtensionNode node = AddinManager.GetExtensionNode(path);
if (node == null)
{
return new T[0];
}
return node.GetExtensionObjects<T>();
}
public virtual IEnumerable<T> GetExtensionNodes<T>(string path)
where T : ExtensionNode
{
TreeNode parentNode = AddinManager.ExtensionTree[path];
if (parentNode == null)
{
yield break;
}
foreach (TreeNode childNode in parentNode)
{
T node = childNode.ExtensionNode as T;
if (node != null)
{
yield return node;
}
}
}
public virtual Image GetImage(string imageName)
{
return GDIObjectManager.Instance.GetBitmap(imageName);
}
}
}