Beispiel #1
0
        static INode ReadNode(XmlReader reader, bool nested = false)
        {
            var skipFirstRead = nested;

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            var          name  = reader.Name;
            List <INode> nodes = new List <INode>();
            INode        node  = null;

            while (skipFirstRead || reader.Read())
            {
                skipFirstRead = false;

                switch (reader.NodeType)
                {
                case XmlNodeType.EndElement:
                    Debug.Assert(reader.Name == name);
                    if (nodes.Count == 0)     //Empty element
                    {
                        return(null);
                    }
                    if (nodes.Count == 1)
                    {
                        return(nodes[0]);
                    }
                    return(new ListNode(nodes, (IXmlNamespaceResolver)reader, ((IXmlLineInfo)reader).LineNumber,
                                        ((IXmlLineInfo)reader).LinePosition));

                case XmlNodeType.Element:
                    var isEmpty        = reader.IsEmptyElement && reader.Name == name;
                    var elementName    = reader.Name;
                    var elementNsUri   = reader.NamespaceURI;
                    var elementXmlInfo = (IXmlLineInfo)reader;
                    IList <KeyValuePair <string, string> > xmlns;

                    var attributes = ParseXamlAttributes(reader, out xmlns);
                    var prefixes   = PrefixesToIgnore(xmlns);

                    IList <XmlType> typeArguments = null;
                    if (attributes.Any(kvp => kvp.Key == XmlName.xTypeArguments))
                    {
                        typeArguments =
                            ((ValueNode)attributes.First(kvp => kvp.Key == XmlName.xTypeArguments).Value).Value as IList <XmlType>;
                    }

                    node = new ElementNode(new XmlType(elementNsUri, elementName, typeArguments), elementNsUri,
                                           reader as IXmlNamespaceResolver, elementXmlInfo.LineNumber, elementXmlInfo.LinePosition);
                    ((IElementNode)node).Properties.AddRange(attributes);
                    (node.IgnorablePrefixes ?? (node.IgnorablePrefixes = new List <string>()))?.AddRange(prefixes);

                    ParseXamlElementFor((IElementNode)node, reader);
                    nodes.Add(node);
                    if (isEmpty || nested)
                    {
                        return(node);
                    }
                    break;

                case XmlNodeType.Text:
                    node = new ValueNode(reader.Value.Trim(), (IXmlNamespaceResolver)reader, ((IXmlLineInfo)reader).LineNumber,
                                         ((IXmlLineInfo)reader).LinePosition);
                    nodes.Add(node);
                    break;

                case XmlNodeType.Whitespace:
                    break;

                default:
                    Debug.WriteLine("Unhandled node {0} {1} {2}", reader.NodeType, reader.Name, reader.Value);
                    break;
                }
            }
            throw new XamlParseException("Closing PropertyElement expected", (IXmlLineInfo)reader);
        }
 public void Visit(ValueNode node, INode parentNode)
 {
     scopes[node] = scopes[parentNode];
 }
Beispiel #3
0
 public void Visit(ValueNode node, INode parentNode) => action(node, parentNode);
 public void Visit(ValueNode node, INode parentNode)
 {
 }
Beispiel #5
0
 public void Visit(ValueNode node, INode parentNode)
 {
     Values[node] = node.Value;
 }