void RaiseChanged <T>(ComponentHandler <T> handler, Entity entity, Option <T> previousOption, Option <T> currentOption) where T : IComponent { T current; var hasValue = currentOption.TryGet(out current); T previous; var hasPrevious = previousOption.TryGet(out previous); if (hasValue) { if (!hasPrevious) { handler.RaiseAdded(entity, current); Added?.Invoke(entity, current); } } else if (hasPrevious) { handler.RaiseRemoved(entity, previous); Removed?.Invoke(entity, previous); } handler.RaiseChanged(entity, previousOption, currentOption); Changed?.Invoke(entity, previousOption.Cast <IComponent>(), currentOption.Cast <IComponent>()); }