Danmaku_no_Kyojin.BulletEngine.BulletMLNode.StringToName C# (CSharp) Method

StringToName() private static method

Convert a string to it's ENodeName enum equivalent
private static StringToName ( string str ) : ENodeName
str string The string to convert to an enum
return ENodeName
        private static ENodeName StringToName(string str)
        {
            return (ENodeName)Enum.Parse(typeof(ENodeName), str);
        }

Usage Example

示例#1
0
        /// <summary>
        /// Parse the specified bulletNodeElement.
        /// Read all the data from the xml node into this dude.
        /// </summary>
        /// <param name="bulletNodeElement">Bullet node element.</param>
        public bool Parse(XmlNode bulletNodeElement, BulletMLNode parentNode)
        {
            Debug.Assert(null != bulletNodeElement);

            //grab the parent node
            Parent = parentNode;

            //get the node type
            Name = BulletMLNode.StringToName(bulletNodeElement.Name);

            //Parse all our attributes
            XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes;

            for (int i = 0; i < mapAttributes.Count; i++)
            {
                string strName  = mapAttributes.Item(i).Name;
                string strValue = mapAttributes.Item(i).Value;

                if ("type" == strName)
                {
                    //skip the type attribute in top level nodes
                    if (ENodeName.bulletml == Name)
                    {
                        continue;
                    }

                    //get the bullet node type
                    NodeType = BulletMLNode.StringToType(strValue);
                }
                else if ("label" == strName)
                {
                    //label is just a text value
                    Label = strValue;
                }
            }

            //parse all the child nodes
            if (bulletNodeElement.HasChildNodes)
            {
                for (XmlNode childNode = bulletNodeElement.FirstChild;
                     null != childNode;
                     childNode = childNode.NextSibling)
                {
                    //if the child node is a text node, parse it into this dude
                    if (XmlNodeType.Text == childNode.NodeType)
                    {
                        //Get the text of the child xml node, but store it in THIS bullet node
                        NodeEquation.Parse(childNode.Value);
                        continue;
                    }

                    //create a new node
                    BulletMLNode childBulletNode = new BulletMLNode();

                    //read in the node
                    if (!childBulletNode.Parse(childNode, this))
                    {
                        return(false);
                    }

                    //store the node
                    ChildNodes.Add(childBulletNode);
                }
            }

            return(true);
        }