internal BranchedTable(XmlNode node, RandTableType rtType) { _type = rtType; IEnumerator ie = node.ChildNodes.GetEnumerator(); while (ie.MoveNext()) { XmlNode cn = (XmlNode)ie.Current; if (cn.Name.Equals("branch")) { int weight = 1; string str = null; try { str = cn.Attributes["weight"].Value; } catch {} if (str != null) { try { weight = int.Parse(str); if (weight < 1) { throw new FormatException("invalid weight :" + str); } } catch { throw new FormatException("invalid weight :" + str); } } add(Parse(cn, rtType), weight); } } }
private object Parse(XmlNode node, RandTableType rtType) { switch (rtType) { case RandTableType.ACTION: ArrayedAction aArray = new ArrayedAction(node); // if single action, regists non-arrayed action object. if (aArray.Count == 1) { return(aArray[0]); } else { return(aArray); } case RandTableType.EFFECT: ArrayedEffect eArray = new ArrayedEffect(node); // if single action, regists non-arrayed action object. if (eArray.Count == 1) { return(eArray[0]); } else { return(eArray); } case RandTableType.TARGET: ArrayedTarget tArray = new ArrayedTarget(node); // if single action, regists non-arrayed action object. if (tArray.Count == 1) { return(tArray[0]); } else { return(tArray); } default: throw new FormatException("Invalid type attribute in the randomized tag"); break; } return(null); }
internal ForEachTable(XmlNode node, RandTableType rtType) { _type = rtType; string attr = node.Attributes["for_each"].Value; if (attr.Equals("business")) { target = TargetType.BUSINESS; } else if (attr.Equals("company")) { target = TargetType.COMPANY; } else { throw new FormatException("invalid 'for_each' target :" + attr); } }
static internal RandomTable CreateTable(XmlNode node, RandTableType tableType) { RandomTable newTable; try { string attr = node.Attributes["for_each"].Value; if (tableType != RandTableType.TARGET) { throw new FormatException("The 'for_each' attribute is available only in the target definition."); } else { newTable = new ForEachTable(node, tableType); } } catch (NullReferenceException nre) { newTable = new BranchedTable(node, tableType); } newTable._type = tableType; return(newTable); }