public virtual void RemoveMember(Player player) { if (! IsPlayerAlreadyInTeam(player)) throw new InvalidOperationException("Player not in team!"); if (player.Equals(TwelfthMan)) { twelfthMan = null; } else { members.Remove(player); } }
public virtual bool IsPlayerAlreadyInTeam(Player player) { // notice I can use Contains() and Equals() instead of digging down to ID's. // this also works for value objects. Implement Equals()! return members.Contains(player) || player.Equals(TwelfthMan); }