Inheritance: ImplicitModuleBase
コード例 #1
0
ファイル: ImplicitXmlChain.cs プロジェクト: JPMMaia/tuguiadas
        public static ImplicitSelect SelectFromXElement(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);
            var falloff      = (xElement.Attribute("falloff") != null ? xElement.Attribute("falloff").Value : String.Empty);
            var threshold    = (xElement.Attribute("threshold") != null ? xElement.Attribute("threshold").Value : String.Empty);

            ImplicitSelect @select;

            ImplicitModuleBase source;
            Double             value;

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

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

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

            if (!String.IsNullOrEmpty(falloff))
            {
                if (chain.Modules.TryGetValue(falloff, out source))
                {
                    @select.Falloff = source;
                }
                else if (Double.TryParse(falloff, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    @select.Falloff = value;
                }
                else
                {
                    throw new InvalidOperationException("Invalid falloff value");
                }
            }

            if (!String.IsNullOrEmpty(threshold))
            {
                if (chain.Modules.TryGetValue(threshold, out source))
                {
                    @select.Threshold = source;
                }
                else if (Double.TryParse(threshold, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                {
                    @select.Threshold = value;
                }
                else
                {
                    throw new InvalidOperationException("Invalid threshold value");
                }
            }

            return(@select);
        }
コード例 #2
0
        public static ImplicitSelect SelectFromXElement(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);
            var falloff = (xElement.Attribute("falloff") != null ? xElement.Attribute("falloff").Value : String.Empty);
            var threshold = (xElement.Attribute("threshold") != null ? xElement.Attribute("threshold").Value : String.Empty);

            ImplicitSelect @select;

            ImplicitModuleBase source;
            Double value;

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

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

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

            if (!String.IsNullOrEmpty(falloff))
            {
                if (chain.Modules.TryGetValue(falloff, out source))
                    @select.Falloff = source;
                else if (Double.TryParse(falloff, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                    @select.Falloff = value;
                else
                    throw new InvalidOperationException("Invalid falloff value");
            }

            if (!String.IsNullOrEmpty(threshold))
            {
                if (chain.Modules.TryGetValue(threshold, out source))
                    @select.Threshold = source;
                else if (Double.TryParse(threshold, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                    @select.Threshold = value;
                else
                    throw new InvalidOperationException("Invalid threshold value");
            }

            return @select;
        }