54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using JD.LogService;
|
|
using JD.TeaBoxAddinSystem.Addins.Description;
|
|
using JD.TeaBoxAddinSystem.Addins.Internal;
|
|
|
|
namespace JD.TeaBoxAddinSystem.Addins
|
|
{
|
|
/// <summary>
|
|
/// A lazy-obtained resource.
|
|
/// </summary>
|
|
public class LazyResourceReference<T> : LazyReference<T>
|
|
{
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
/// <param name="node"></param>
|
|
/// <param name="resourcename"></param>
|
|
public LazyResourceReference(Node node, string resourcename)
|
|
: base(node, resourcename)
|
|
{ }
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Creates the value.
|
|
/// </summary>
|
|
/// <param name="resources"></param>
|
|
/// <param name="resourceName"></param>
|
|
/// <returns></returns>
|
|
protected virtual T CreateValue(IResources resources, string resourceName)
|
|
{
|
|
return (T)resources.GetObject(resourceName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates an instance from the module.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected override T LoadValue()
|
|
{
|
|
T value = CreateValue(Node.Module.Resources, ResourceName);
|
|
if (ReferenceEquals(value, null))
|
|
{
|
|
AddinManager.Log(new Error(LogCategory.Error, "Unable to create the resource named '{0}'.", ResourceName) { Origin = FileLocation });
|
|
}
|
|
return value;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|