Constant<T>
Allows to use constant values as generic parameters.
namespace DotNext.Generic
{
public abstract class Constant<T>
{
private readonly T Value;
protected Constant(T constVal)
{
Value = constVal;
}
public sealed override string ToString()
{
object obj = Value;
if (obj != null)
return obj.ToString();
return "NULL";
}
public sealed override int GetHashCode()
{
return ((object)Value)?.GetHashCode() ?? 0;
}
public sealed override bool Equals(object other)
{
if (other is T) {
T val = (T)other;
return object.Equals(val, Value);
}
Constant<T> constant = other as Constant<T>;
if (constant != null)
return object.Equals(Value, constant.Value);
return false;
}
public static implicit operator T(Constant<T> const)
{
return const.Value;
}
}
}