using System.Collections.Generic; namespace Chernobyl.DesignPatterns.Visitor { /// /// This visitor counts the number of hosts /// it visits. /// /// The type of the host that this /// visitor will be visiting. public class CountVisitor : IVisitor where HostType : IHost> { /// /// Constructor. /// /// The enumerator to use to move through /// the hosts. public CountVisitor(IEnumerator enumerator) { Enumerator = enumerator; // start visiting the hosts6 do { Enumerator.Current.Accept(this); } while (Enumerator.MoveNext() != false); } /// /// Visits a host and updates it's counter. /// /// The host to visit public void Visit(HostType host) { ++Count; } /// /// The number of hosts this visitor has visited. /// public uint Count { get; protected set; } /// /// Enumerates through the hosts. /// IEnumerator Enumerator { get; set; } } }