示例#1
0
        static bool ParseInput(XmlNode inputNode, List <CapnpGen.CapInput> inputs, out string error)
        {
            error = "";
            CapnpGen.CapInput input = new CapnpGen.CapInput();

            string name = "";

            if (!TryGetAttribute(inputNode, "name", out name))
            {
                error = "Input node does not have a name attribute";
                return(false);
            }
            input.Name = name;

            CapnpGen.CapInputType inputType = CapnpGen.CapInputType.position;
            if (!TryGetAttribute(inputNode, "type", out inputType))
            {
                error = "Input node \"" + input.Name + "\" does not have a valid type attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapInputType));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            input.Type = inputType;

            inputs.Add(input);
            return(true);
        }
示例#2
0
        static bool TryGetAttribute(XmlNode node, string attribute, out CapnpGen.CapInputType value)
        {
            value = CapnpGen.CapInputType.position;

            if (node.Attributes[attribute] == null)
            {
                return(false);
            }

            return(Enum.TryParse <CapnpGen.CapInputType>(node.Attributes[attribute].Value, out value));
        }