Exemplo n.º 1
0
        private static TableEntry HandleIntType(XElement caseElement)
        {
            double gpa   = GetBaseGpa(caseElement);
            bool   bonus = GetBonusStatus(caseElement);

            if (caseElement.Name == "range")
            {
                int?lower, upper;

                string lowerStr = XmlHelper.GetAttributeValueOrDefault(caseElement, "lower");
                string upperStr = XmlHelper.GetAttributeValueOrDefault(caseElement, "upper");

                if (!StringParser.TryParseIntNullable(lowerStr, out lower))
                {
                    throw XmlHelper.CreateException(caseElement, "Invalid lower score range int value: " + lowerStr);
                }
                if (!StringParser.TryParseIntNullable(upperStr, out upper))
                {
                    throw XmlHelper.CreateException(caseElement, "Invalid upper score range int value: " + upperStr);
                }
                if (lower == null && upper == null)
                {
                    throw XmlHelper.CreateException(caseElement, "Must specify either at least one bound");
                }

                IntTableRange range = new IntTableRange(lower, upper, gpa, bonus);
                Debug.WriteLine("> Loading <int> range: " + range);
                return(range);
            }

            if (caseElement.Name == "item")
            {
                int    value;
                string valueStr = XmlHelper.GetAttributeValue(caseElement, "value");
                if (!int.TryParse(valueStr, out value))
                {
                    throw XmlHelper.CreateException(caseElement, "Invalid score case int value: " + valueStr);
                }
                IntTableItem item = new IntTableItem(value, gpa, bonus);
                Debug.WriteLine("> Loading <int> item: " + item);
                return(item);
            }

            throw XmlHelper.CreateException(caseElement, "Invalid score case type: " + caseElement.Name);
        }
Exemplo n.º 2
0
        private static TableEntry HandleIntType(XElement caseElement)
        {
            double gpa = GetBaseGpa(caseElement);
            bool bonus = GetBonusStatus(caseElement);

            if (caseElement.Name == "range")
            {
                int? lower, upper;

                string lowerStr = XmlHelper.GetAttributeValueOrDefault(caseElement, "lower");
                string upperStr = XmlHelper.GetAttributeValueOrDefault(caseElement, "upper");

                if (!StringParser.TryParseIntNullable(lowerStr, out lower))
                    throw XmlHelper.CreateException(caseElement, "Invalid lower score range int value: " + lowerStr);
                if (!StringParser.TryParseIntNullable(upperStr, out upper))
                    throw XmlHelper.CreateException(caseElement, "Invalid upper score range int value: " + upperStr);
                if (lower == null && upper == null)
                    throw XmlHelper.CreateException(caseElement, "Must specify either at least one bound");
                
                IntTableRange range = new IntTableRange(lower, upper, gpa, bonus);
                Debug.WriteLine("> Loading <int> range: " + range);
                return range;
            }

            if (caseElement.Name == "item")
            {
                int value;
                string valueStr = XmlHelper.GetAttributeValue(caseElement, "value");
                if (!int.TryParse(valueStr, out value))
                    throw XmlHelper.CreateException(caseElement, "Invalid score case int value: " + valueStr);
                IntTableItem item = new IntTableItem(value, gpa, bonus);
                Debug.WriteLine("> Loading <int> item: " + item);
                return item;
            }

            throw XmlHelper.CreateException(caseElement, "Invalid score case type: " + caseElement.Name);
        }