public ISubtractableTag SubtractTag(ISubtractableTag tag) { if (tag == null) { throw new ArgumentNullException(nameof(tag)); } IntValueTag that = tag as IntValueTag; if (that == null) { throw new InvalidRulesException($"Tried to subtract tags of different types '{RenderForLog()}' and '{tag.RenderForLog()}'."); } return(new IntValueTag(Key, Value - that.Value, Duration)); }
public override void AddTag(TagBase tag) { if (!(tag is ISubtractableTag)) { throw new InvalidRulesException($"Tried to sum non-subtractable tag '{tag.RenderForLog()}' on '{Owner.RenderForLog()}'."); } ISubtractableTag newTag = null; foreach (ISubtractableTag that in Tags.Append(tag).Where(x => x.Key == tag.Key).OfType <ISubtractableTag>()) { newTag = newTag == null ? that : newTag.SubtractTag(that); } Tags.RemoveAll(x => x.Key == tag.Key); Tags.Add((TagBase)newTag); }