Given the interfaces:
public interface IStorable<TPk>
{
TPk ID { get; set; }
...
}
And
public interface ICacheHolder<TCached,TPk> where TCached : IStorable<TPk>
{
...
TCached GetValueByID(TPk id);
...
}
And the concrete implementation:
public class BasicCacheHolder<TCached, TPk>: ICacheHolder<TCached, TPk> where TCached : IStorable<TPk>
{
...
public TCached GetValueByID(TPk id)
{
return CacheEntries.SingleOrDefault(ce => ce.Value.ID == id);
}
}
I get the error that "Operator '==' cannot be applied to the operands of type 'TPk' and 'TPk', Cannot apply operator '==' to operands of type 'TPk' and 'TPk'"
I assume this is because one of the TPk generic types is hiding the reference to the other TPk, but attempting to rename them appears to break my code.
How do I fix this issue?
EDIT
CachedEntry is a very simple class of the following:
public class CacheEntry<T>
{
public T Value { get; set; }
public DateTime RetrievedAt { get; set; }
}