public int CompareTo(CostCentre other) { if (other == null) { return(1); } var result = 0; if (result == 0) { result = Tier1.NullSafeCompareTo(other.Tier1); } if (result == 0) { result = Tier2.NullSafeCompareTo(other.Tier2); } if (result == 0) { result = Tier3.NullSafeCompareTo(other.Tier3); } if (result == 0) { result = Tier4.NullSafeCompareTo(other.Tier4); } if (result == 0) { result = Code.NullSafeCompareTo(other.Code); } return(result); }
public override int GetHashCode() { unchecked { int hash = (int)2166136261; hash = hash * 16777619 ^ Tier1?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Tier2?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Tier3?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Tier4?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Code?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Tier1Name?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Tier2Name?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Tier3Name?.GetHashCode() ?? 0; hash = hash * 16777619 ^ Tier4Name?.GetHashCode() ?? 0; hash = hash * 16777619 ^ CostCentreName?.GetHashCode() ?? 0; return(hash); } }
static void Main(string[] args) { Console.WriteLine("Starting 'ChainOfResponsibility' Design Pattern Application!"); //Prepare our chain of responsibility Tier1 Max = new Tier1(); Tier2 Jane = new Tier2(); Tier3 John = new Tier3(); Tier4 Boss = new Tier4(); Max.SetSuccessor(Jane); Jane.SetSuccessor(John); John.SetSuccessor(Boss); //Simulate different ticket types //Basic Ticket SupportTicket sampleTicket = new SupportTicket(1, TicketType.Basic); Max.HandleRequest(sampleTicket); //InDepth Ticket sampleTicket = new SupportTicket(2, TicketType.InDepth); Max.HandleRequest(sampleTicket); //Advanced Ticket sampleTicket = new SupportTicket(3, TicketType.Advanced); Max.HandleRequest(sampleTicket); //Vendor Ticket sampleTicket = new SupportTicket(4, TicketType.Vendor); Max.HandleRequest(sampleTicket); //Unknown Ticket sampleTicket = new SupportTicket(99, TicketType.Unknown); Max.HandleRequest(sampleTicket); Console.ReadLine(); }