CatEye.Core.Tone.DeserializeFromXML C# (CSharp) Method

DeserializeFromXML() public method

public DeserializeFromXML ( XmlNode node ) : void
node System.Xml.XmlNode
return void
        public void DeserializeFromXML(XmlNode node)
        {
            if (node.Name != "Tone")
                throw new IncorrectNodeException("Node should have name \"Tone\"");

            double res = 0;
            if (node.Attributes["R"] != null)
            {
                if (double.TryParse(node.Attributes["R"].Value, NumberStyles.Float, nfi, out res))
                {
                    mR = res;
                }
                else
                    throw new IncorrectNodeValueException("Can't parse R value");
            }
            if (node.Attributes["G"] != null)
            {
                if (double.TryParse(node.Attributes["G"].Value, NumberStyles.Float, nfi, out res))
                {
                    mG = res;
                }
                else
                    throw new IncorrectNodeValueException("Can't parse G value");
            }
            if (node.Attributes["B"] != null)
            {
                if (double.TryParse(node.Attributes["B"].Value, NumberStyles.Float, nfi, out res))
                {
                    mB = res;
                }
                else
                    throw new IncorrectNodeValueException("Can't parse B value");
            }
        }

Usage Example

        public override void DeserializeFromXML(XmlNode node)
        {
            base.DeserializeFromXML(node);
            foreach (XmlNode xn in node.ChildNodes)
            {
                if (xn.Name == "Tone" &&
                    xn.Attributes["Name"] != null &&
                    xn.Attributes["Name"].Value == "DarkTone")
                {
                    mDarkTone.DeserializeFromXML(xn);
                }
                if (xn.Name == "Tone" &&
                    xn.Attributes["Name"] != null &&
                    xn.Attributes["Name"].Value == "LightTone")
                {
                    mLightTone.DeserializeFromXML(xn);
                }
                if (xn.Name == "Point" &&
                    xn.Attributes["Name"] != null &&
                    xn.Attributes["Name"].Value == "AutoDarkCenter")
                {
                    mAutoDarkCenter.DeserializeFromXML(xn);
                }
                if (xn.Name == "Point" &&
                    xn.Attributes["Name"] != null &&
                    xn.Attributes["Name"].Value == "AutoLightCenter")
                {
                    mAutoLightCenter.DeserializeFromXML(xn);
                }
            }

            double res = 0;

            if (node.Attributes["Edge"] != null)
            {
                if (double.TryParse(node.Attributes["Edge"].Value, NumberStyles.Float, nfi, out res))
                {
                    mEdge = res;
                }
                else
                {
                    throw new IncorrectNodeValueException("Can't parse Edge value");
                }
            }

            res = 0;
            if (node.Attributes["Softness"] != null)
            {
                if (double.TryParse(node.Attributes["Softness"].Value, NumberStyles.Float, nfi, out res))
                {
                    mSoftness = res;
                }
                else
                {
                    throw new IncorrectNodeValueException("Can't parse Softness value");
                }
            }

            res = 0;
            if (node.Attributes["AutoDarkRadius"] != null)
            {
                if (double.TryParse(node.Attributes["AutoDarkRadius"].Value, NumberStyles.Float, nfi, out res))
                {
                    mAutoDarkRadius = res;
                }
                else
                {
                    throw new IncorrectNodeValueException("Can't parse AutoDarkRadius value");
                }
            }

            res = 0;
            if (node.Attributes["AutoLightRadius"] != null)
            {
                if (double.TryParse(node.Attributes["AutoLightRadius"].Value, NumberStyles.Float, nfi, out res))
                {
                    mAutoLightRadius = res;
                }
                else
                {
                    throw new IncorrectNodeValueException("Can't parse AutoLightRadius value");
                }
            }

            bool bres = false;

            if (node.Attributes["AutoDarkTone"] != null)
            {
                if (bool.TryParse(node.Attributes["AutoDarkTone"].Value, out bres))
                {
                    mAutoDarkTone = bres;
                }
                else
                {
                    throw new IncorrectNodeValueException("Can't parse AutoDarkTone value");
                }
            }

            bres = false;
            if (node.Attributes["AutoLightTone"] != null)
            {
                if (bool.TryParse(node.Attributes["AutoLightTone"].Value, out bres))
                {
                    mAutoLightTone = bres;
                }
                else
                {
                    throw new IncorrectNodeValueException("Can't parse AutoLightTone value");
                }
            }

            OnChanged();
        }