I get the compiler error when trying to compare generic enums. All looks fine and I don't know what's wrong.
Error message: Operator == cannot be applied to operands of type T and T
public class SpriteLink<T>
{
public T id;
public Sprite sprite;
public SpriteLink(T id, Sprite sprite)
{
this.id = id;
this.sprite = sprite;
}
}
public class LinkList<T>
{
public List<SpriteLink<T>> links = new List<SpriteLink<T>>();
public bool Contains(T id)
{
links[0].id = id; // compiler passes this line without any errors
return links.Any(link => link.id == id); // but throws compiler error here (why?)
}
public bool Set(T id, Sprite sprite)
{
if (!Contains(id))
{
links.Add(new SpriteLink<T>(id, sprite));
return true;
}
return false;
}
}
public LinkList<SurfaceID> surfaceLinks = new LinkList<SurfaceID>();
public LinkList<FloorID> floorLinks = new LinkList<FloorID>();
SurfaceID
and FloorID
are just enums with some fields.