/// <summary> /// Generates a match object from its XML representation. /// </summary> /// <param name="reader"></param> public void ReadXml(System.Xml.XmlReader reader) { if (reader.Name != "Statistics") { throw new Exception("Unexpected node encountered, Statistics expected"); } while (reader.Name.StartsWith("Statistic") && reader.NodeType == System.Xml.XmlNodeType.Element) { if (reader.Name == "Statistic") { String _Contestant = reader.GetAttribute("Contestant"); String _Item = reader.GetAttribute("Item"); String _Value = reader.GetAttribute("Value"); TennisStatistic newStatistic = new TennisStatistic(); newStatistic.Contestant = int.Parse(_Contestant); newStatistic.Item = (Statistics)System.Enum.Parse(typeof(Statistics), _Item); newStatistic.Value = int.Parse(_Value); Items.Add(newStatistic); } reader.Read(); } }
/// <summary> /// Increments the specified statitic for the contestant with the specified Delta value; /// </summary> /// <param name="Item"></param> /// <param name="Contestant"></param> /// <param name="Delta"></param> private void SetItem(Statistics Item, int Contestant, int Value) { Boolean Found; Found = false; foreach (TennisStatistic item in Items) { if (item.Item == Item && item.Contestant == Contestant) { item.Value = Value; Found = true; } } if (!Found) { TennisStatistic newItem = new TennisStatistic(Item); newItem.Contestant = Contestant; newItem.Value = Value; Items.Add(newItem); } }
/// <summary> /// Increments the specified statitic for the contestant with the specified Delta value; /// </summary> /// <param name="Item"></param> /// <param name="Contestant"></param> /// <param name="Delta"></param> private void IncrementItem(Statistics Item, int Contestant, int Delta) { Boolean Found; Found = false; foreach (TennisStatistic item in Items) { if (item.Item == Item && item.Contestant == Contestant) { item.Value += Delta; Found = true; } } if (!Found) { TennisStatistic newItem = new TennisStatistic(Item); newItem.Contestant = Contestant; newItem.Value = Delta > 0 ? Delta : 0; Items.Add(newItem); } }