TryGetValueAsInt() public static method

Parse the inner text of element with the given name as an integer. If element is missing or parsing fails then returns null.
public static TryGetValueAsInt ( XmlElement xmlParent, string elemName ) : int?
xmlParent System.Xml.XmlElement
elemName string
return int?
        /// <summary>
        /// Create a complexity regulation strategy based on the provided XML config values.
        /// </summary>
        public static IComplexityRegulationStrategy CreateComplexityRegulationStrategy(XmlElement xmlConfig, string complexityElemName)
        {
            // Get root activation element.
            XmlNodeList nodeList = xmlConfig.GetElementsByTagName(complexityElemName, "");

            if (nodeList.Count != 1)
            {
                throw new ArgumentException("Missing or invalid complexity XML config setting.");
            }

            XmlElement xmlComplexity = nodeList[0] as XmlElement;

            string complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlComplexity, "ComplexityRegulationStrategy");
            int?   complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlComplexity, "ComplexityThreshold");

            ComplexityCeilingType ceilingType;

            if (!Enum.TryParse <ComplexityCeilingType>(complexityRegulationStr, out ceilingType))
            {
                return(new NullComplexityRegulationStrategy());
            }

            if (null == complexityThreshold)
            {
                throw new ArgumentNullException("threshold", string.Format("threshold must be provided for complexity regulation strategy type [{0}]", ceilingType));
            }

            return(new DefaultComplexityRegulationStrategy(ceilingType, complexityThreshold.Value));
        }
Beispiel #2
0
        /// <summary>
        /// Read Parallel Extensions options from config XML.
        /// </summary>
        /// <param name="xmlConfig"></param>
        /// <returns></returns>
        public static ParallelOptions ReadParallelOptions(XmlElement xmlConfig)
        {
            // Get parallel options.
            ParallelOptions parallelOptions;
            int?            maxDegreeOfParallelism = XmlUtils.TryGetValueAsInt(xmlConfig, "MaxDegreeOfParallelism");

            if (null != maxDegreeOfParallelism)
            {
                parallelOptions = new ParallelOptions {
                    MaxDegreeOfParallelism = maxDegreeOfParallelism.Value
                };
            }
            else
            {
                parallelOptions = new ParallelOptions();
            }
            return(parallelOptions);
        }