Inheritance: ImplicitModuleBase
Ejemplo n.º 1
0
        public static ImplicitAutoCorrect AutoCorrectFromXElement(ImplicitXmlChain chain, XElement xElement)
        {
            var sourceString = (xElement.Attribute("source") != null ? xElement.Attribute("source").Value : String.Empty);
            var low          = (xElement.Attribute("low") != null ? xElement.Attribute("low").Value : String.Empty);
            var high         = (xElement.Attribute("high") != null ? xElement.Attribute("high").Value : String.Empty);

            ImplicitAutoCorrect autoCorrect;

            ImplicitModuleBase source;
            Double             value;

            if (!String.IsNullOrEmpty(sourceString))
            {
                if (chain.Modules.TryGetValue(sourceString, out source))
                {
                    autoCorrect = new ImplicitAutoCorrect(source);
                }
                else if (Double.TryParse(sourceString, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    autoCorrect = new ImplicitAutoCorrect(value);
                }
                else
                {
                    throw new InvalidOperationException("Invalid source value");
                }
            }
            else
            {
                throw new InvalidOperationException("Missing source");
            }

            if (!String.IsNullOrEmpty(low))
            {
                if (Double.TryParse(low, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    autoCorrect.Low = value;
                }
                else
                {
                    throw new InvalidOperationException("Invalid low value");
                }
            }

            if (!String.IsNullOrEmpty(high))
            {
                if (Double.TryParse(high, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    autoCorrect.High = value;
                }
                else
                {
                    throw new InvalidOperationException("Invalid high value");
                }
            }

            return(autoCorrect);
        }
        public static ImplicitAutoCorrect AutoCorrectFromXElement(ImplicitXmlChain chain, XElement xElement)
        {
            var sourceString = (xElement.Attribute("source") != null ? xElement.Attribute("source").Value : String.Empty);
            var low = (xElement.Attribute("low") != null ? xElement.Attribute("low").Value : String.Empty);
            var high = (xElement.Attribute("high") != null ? xElement.Attribute("high").Value : String.Empty);

            ImplicitAutoCorrect autoCorrect;

            ImplicitModuleBase source;
            Double value;

            if (!String.IsNullOrEmpty(sourceString))
            {
                if (chain.Modules.TryGetValue(sourceString, out source))
                    autoCorrect = new ImplicitAutoCorrect(source);
                else if (Double.TryParse(sourceString, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                    autoCorrect = new ImplicitAutoCorrect(value);
                else
                    throw new InvalidOperationException("Invalid source value");
            }
            else
                throw new InvalidOperationException("Missing source");

            if (!String.IsNullOrEmpty(low))
            {
                if (Double.TryParse(low, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                    autoCorrect.Low = value;
                else
                    throw new InvalidOperationException("Invalid low value");
            }

            if (!String.IsNullOrEmpty(high))
            {
                if (Double.TryParse(high, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                    autoCorrect.High = value;
                else
                    throw new InvalidOperationException("Invalid high value");
            }

            return autoCorrect;
        }