So i have an interface named IResource
that consist of those 5 properties as readonly but since I am adding those to a Dictionary<IResource, int>
i need a way to compare two IResource
so i don't have duplicates in the Dictionary. Is there a way for me to add a default Equals(object obj)
to every IResource?
I already added an Equals
Override to the Wood
class and it solved the problem but i would have to add a Equals(object obj)
in every class that implements the IResource
.
public class Wood : IResource
{
public string Package => "Core";
public string Family => "Wood";
public string Name => "Wood";
public bool IsFractal => false;
public ResourceType Type => ResourceType.Natural;
}
PS:I have an override of the Add(IResource key, uint value)
method to the dictionary to check if the IResource
already exists.
public new void Add(IResource key, uint value)
{
if (base.ContainsKey(key))
base[key] += value;
else
base.Add(key, value);
}
Right now when i add a IResource
interface to the dictionary, it always adds a new entry.