public static FruitDefinition FromXml(XmlElement fruitDef) { var type = (FruitType)Enum.Parse(typeof(FruitType), fruitDef.GetAttribute("Type")); int quantity = int.Parse(fruitDef.GetAttribute("Quantity")); int energy = int.Parse(fruitDef.GetAttribute("Energy")); var result = new FruitDefinition(type, quantity, energy); return(result); }
public static RandomFruitDistribution FromXml(XmlElement fruitDistribution) { var result = new RandomFruitDistribution(); if (!Enum.TryParse(fruitDistribution.GetAttribute("PopulationMethod"), out FruitPopulationMethod populationMethod)) { throw new InvalidOperationException("Invalid PopulationMethod value."); } result.PopulationMethod = populationMethod; foreach (XmlElement fruitDef in fruitDistribution.ChildNodes) { var fd = FruitDefinition.FromXml(fruitDef); result._definitions.Add(fd.Type, fd); } return(result); }