Implement equality on TraitPair.

This commit is contained in:
RoosterDragon
2015-12-31 01:38:09 +00:00
parent addbe6d564
commit 3026bdcea5
4 changed files with 17 additions and 10 deletions

View File

@@ -408,14 +408,21 @@ namespace OpenRA
}
}
public struct TraitPair<T>
public struct TraitPair<T> : IEquatable<TraitPair<T>>
{
public Actor Actor;
public T Trait;
public readonly Actor Actor;
public readonly T Trait;
public override string ToString()
{
return "{0}->{1}".F(Actor.Info.Name, Trait.GetType().Name);
}
public TraitPair(Actor actor, T trait) { Actor = actor; Trait = trait; }
public static bool operator ==(TraitPair<T> me, TraitPair<T> other) { return me.Actor == other.Actor && Equals(me.Trait, other.Trait); }
public static bool operator !=(TraitPair<T> me, TraitPair<T> other) { return !(me == other); }
public override int GetHashCode() { return Actor.GetHashCode() ^ Trait.GetHashCode(); }
public bool Equals(TraitPair<T> other) { return this == other; }
public override bool Equals(object obj) { return obj is TraitPair<T> && Equals((TraitPair<T>)obj); }
public override string ToString() { return "{0}->{1}".F(Actor.Info.Name, Trait.GetType().Name); }
}
}