/// <summary>
        /// Writes a <see cref="SlotCollection{TSlot}"/> to the current stream.
        /// </summary>
        /// <typeparam name="TSlot">Type of <see cref="Slot"/> to read.</typeparam>
        /// <param name="writer"><see cref="MessageWriter"/> to use.</param>
        /// <param name="slots">The <see cref="SlotCollection{TSlot}"/> to write.</param>
        public static void WriteSlotCollection <TSlot>(this MessageWriter writer, SlotCollection <TSlot> slots) where TSlot : Slot, new()
        {
            writer.CheckDispose();

            if (slots == null)
            {
                writer.Write(0);
            }
            else
            {
                var count = slots.Count;

                writer.Write(count);
                for (int i = 0; i < count; i++)
                {
                    slots[i].WriteSlot(writer);
                }
            }
        }