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

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

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

                INode node;
                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);
                    var typeArguments = GetTypeArguments(attributes);

                    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:
                case XmlNodeType.CDATA:
                    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 bool IsResourceDictionary(ElementNode node) => typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]);
예제 #3
0
 public bool IsResourceDictionary(ElementNode node) => false;