public void Write(XElement target) { var elts = _root.Values .Select(entry => Write(entry.Root)) .OrderByDescending(GetWeight) .ToArray(); var merged = _root.Values.Aggregate(new Node(null), (a, n) => Merge(a, n.Root)); var totals = new TotalVisitor(); totals.Visit(merged); target.Add(Write(merged)); target.Add(Write(totals._totals)); target.Add(elts); }
static void VisitMain() { var person = new Visitor.Person(); person.Acceptables = new List <IAcceptable>() { new Loan() { MonthlyPayment = 99 }, new Account() { Total = 11 } }; var totalVisitor = new TotalVisitor(); person.Accept(totalVisitor); Console.WriteLine("total is {0}", totalVisitor.Total); }