Exemplo n.º 1
0
        public void Parse(CompileContext context, System.Xml.XmlNode node)
        {
            // We first find the type.
            type = context.ResolveType(node.Prefix, node.LocalName);
            if (!Common.IsTypeSameOrDerived(typeof(IWidget), type))
            {
                throw new ParseException(string.Format("The element must be of type IWidget, " +
                                                       "'{0}' does not implement this interface", type.FullName));
            }

            // Previously, change context was not the same as the type, not they alias.
            changeType = type;

            // Now we try to find name attribute.
            XmlAttribute nameAttr = node.Attributes["Name"];

            if (nameAttr != null)
            {
                name = nameAttr.InnerText;
                if (name.Contains(" "))
                {
                    throw new ParseException("The name contains spaces, invalid.");
                }
            }
            else
            {
                throw new ParseException("Name of widget is required.");
            }

            nameAttr = node.Attributes["Style"];
            if (nameAttr != null)
            {
                styleLink = nameAttr.InnerText;
            }

            // We now go for all other attributes and values.
            foreach (XmlAttribute att in node.Attributes)
            {
                if (att.Name == "Name" || att.Name == "Style")
                {
                    continue;
                }

                ProcessAttribute(context, att);
            }

            foreach (XmlNode node2 in node.ChildNodes)
            {
                ProcessChild(context, node2);
            }

            // Registers a widget.
            context.RegisterWidget(name, this);
        }