Inheritance: ImplicitModuleBase
Example #1
0
        public static ImplicitSphere SphereFromXElement(ImplicitXmlChain chain, XElement xElement)
        {
            var xc     = (xElement.Attribute("xc") != null ? xElement.Attribute("xc").Value : String.Empty);
            var yc     = (xElement.Attribute("yc") != null ? xElement.Attribute("yc").Value : String.Empty);
            var zc     = (xElement.Attribute("zc") != null ? xElement.Attribute("zc").Value : String.Empty);
            var vc     = (xElement.Attribute("vc") != null ? xElement.Attribute("vc").Value : String.Empty);
            var uc     = (xElement.Attribute("uc") != null ? xElement.Attribute("uc").Value : String.Empty);
            var wc     = (xElement.Attribute("wc") != null ? xElement.Attribute("wc").Value : String.Empty);
            var radius = (xElement.Attribute("radius") != null ? xElement.Attribute("radius").Value : String.Empty);

            var sphere = new ImplicitSphere();
            ImplicitModuleBase source;
            Double             value;

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

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

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

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

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

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

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

            return(sphere);
        }
        public static ImplicitSphere SphereFromXElement(ImplicitXmlChain chain, XElement xElement)
        {
            var xc = (xElement.Attribute("xc") != null ? xElement.Attribute("xc").Value : String.Empty);
            var yc = (xElement.Attribute("yc") != null ? xElement.Attribute("yc").Value : String.Empty);
            var zc = (xElement.Attribute("zc") != null ? xElement.Attribute("zc").Value : String.Empty);
            var vc = (xElement.Attribute("vc") != null ? xElement.Attribute("vc").Value : String.Empty);
            var uc = (xElement.Attribute("uc") != null ? xElement.Attribute("uc").Value : String.Empty);
            var wc = (xElement.Attribute("wc") != null ? xElement.Attribute("wc").Value : String.Empty);
            var radius = (xElement.Attribute("radius") != null ? xElement.Attribute("radius").Value : String.Empty);

            var sphere = new ImplicitSphere();
            ImplicitModuleBase source;
            Double value;

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

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

            if (!String.IsNullOrEmpty(zc))
            {

                if (chain.Modules.TryGetValue(zc, out source))
                    sphere.ZCenter = source;
                else if (Double.TryParse(zc, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                    sphere.ZCenter = value;
                else
                    throw new InvalidOperationException("Invalid zc value");
            }

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

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

            if (!String.IsNullOrEmpty(wc))
            {

                if (chain.Modules.TryGetValue(wc, out source))
                    sphere.WCenter = source;
                else if (Double.TryParse(wc, NumberStyles.Any, CultureInfo.InvariantCulture, out value))
                    sphere.WCenter = value;
                else
                    throw new InvalidOperationException("Invalid wc value");
            }

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

            return sphere;
        }