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

92 lines
2.3 KiB
C#

using System;
using JD.Kernel.Classes;
using JD.Kernel.StaticHelpers;
using JD.Kernel.Structs;
using JD.TeaBoxAddinSystem.Addins.Internal;
namespace JD.TeaBoxAddinSystem.Addins
{
/// <summary>
/// Base class for all lazy references.
/// </summary>
[LazyReferenceConverter]
public abstract class LazyReference<T> : Reference<T>, IEquatable<LazyReference<T>>
{
#region Variables
private readonly Node m_node;
private readonly string m_resourceName;
#endregion
#region Constructor
/// <summary>
/// Constructor.
/// </summary>
/// <param name="node"></param>
/// <param name="resourcename"></param>
public LazyReference(Node node, string resourcename)
{
Throw.IfNull(node, "node");
Throw.IfEmpty(resourcename, "resourcename");
m_node = node;
m_resourceName = resourcename;
}
/// <summary>
/// Copy constructor.
/// </summary>
/// <param name="reference"></param>
protected LazyReference(LazyReference<T> reference)
{
System.Diagnostics.Debug.Assert(reference != null);
m_node = reference.m_node;
m_resourceName = reference.m_resourceName;
}
#endregion
#region Properties
/// <summary>
/// Gets the file location to log an error.
/// </summary>
public string ResourceName
{
get { return m_resourceName; }
}
/// <summary>
/// Gets the file location to log an error.
/// </summary>
protected FileLocation FileLocation
{
get { return m_node.FileLocation; }
}
/// <summary>
/// Gets the node associated with the lazy reference.
/// </summary>
protected Node Node
{
get { return m_node; }
}
#endregion
#region IEquatable<LazyReference<T>> Members
bool IEquatable<LazyReference<T>>.Equals(LazyReference<T> other)
{
return other != null &&
other.GetType() == GetType() &&
other.m_node == m_node &&
other.m_resourceName == m_resourceName;
}
#endregion
}
}