TryGetValueAsString() public static method

Read the inner text of element with the given name. If element is missing then returns null.
public static TryGetValueAsString ( XmlElement xmlParent, string elemName ) : string
xmlParent System.Xml.XmlElement
elemName string
return string
示例#1
0
        /// <summary>
        /// Create a network activation scheme from the scheme setting in the provided config XML.
        /// </summary>
        /// <returns></returns>
        public static NetworkActivationScheme CreateActivationScheme(XmlElement xmlConfig, string activationElemName)
        {
            // Get root activation element.
            XmlNodeList nodeList = xmlConfig.GetElementsByTagName(activationElemName, "");

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

            XmlElement xmlActivation = nodeList[0] as XmlElement;
            string     schemeStr     = XmlUtils.TryGetValueAsString(xmlActivation, "Scheme");

            switch (schemeStr)
            {
            case "Acyclic":
                return(NetworkActivationScheme.CreateAcyclicScheme());

            case "CyclicFixedIters":
                int iters = XmlUtils.GetValueAsInt(xmlActivation, "Iters");
                return(NetworkActivationScheme.CreateCyclicFixedTimestepsScheme(iters));

            case "CyclicRelax":
                double deltaThreshold = XmlUtils.GetValueAsInt(xmlActivation, "Threshold");
                int    maxIters       = XmlUtils.GetValueAsInt(xmlActivation, "MaxIters");
                return(NetworkActivationScheme.CreateCyclicRelaxingActivationScheme(deltaThreshold, maxIters));
            }
            throw new ArgumentException(string.Format("Invalid or missing ActivationScheme XML config setting [{0}]", schemeStr));
        }
        /// <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));
        }