using System.Collections.Generic;
public static string GetCfg() {
<cfg address='1009 Broad St.'>
<add name='Living' maximum-occupancy='12' />
<add name='Kitchen' maximum-occupancy='8' />
<add name='Bath' maximum-occupancy='2' />
public static void Main() {
var cfg = new Home(GetCfg());
Console.WriteLine("There are {0} errors. Everything is fine with your home.", cfg.Errors().Length);
Console.WriteLine("---");
cfg = new Home(GetCfg(), new BsDetector());
Console.WriteLine("There is {0} error. Let me explain:", cfg.Errors().Length);
foreach(var error in cfg.Errors()){
Console.WriteLine(error);
public Home(string cfg, params IDependency[] dependencies):base(dependencies){
public string Address {get;set;}
public List<Room> Rooms {get; set;}
public string Name {get; set;}
public int MaximumOccupancy {get; set;}
class BsDetector : ICustomizer {
public void Customize(string collection, INode node, IDictionary<string,string> parameters, ILogger logger){
if(collection != "rooms")
var name = node.Attributes.First(a=>a.Name == "name").Value.ToString();
var maxOccupancy = Convert.ToInt32(node.Attributes.First(a=>a.Name == "maximum-occupancy").Value);
logger.Error("You may not put more than 10 people in your {0} room. You have {1}, and that's {2} too many.", name, maxOccupancy, maxOccupancy - 10);
public void Customize(INode root, IDictionary<string,string> parameters, ILogger logger){}