Exemple #1
0
        bool MoveToNextStoredMember()
        {
            if (MoveToNextMarkupExtensionAttributeMember())
            {
                return(true);
            }

            if (stored_member_enumerator != null)
            {
                // FIXME: value might have to be deserialized.
                switch (node_type)
                {
                case XamlNodeType.StartObject:
                case XamlNodeType.EndMember:
                    // -> StartMember
                    if (stored_member_enumerator.MoveNext())
                    {
                        current   = current_member = stored_member_enumerator.Current.Key;
                        node_type = XamlNodeType.StartMember;
                        return(true);
                    }
                    break;

                case XamlNodeType.StartMember:
                    // -> Value or StartObject (of MarkupExtension)
                    var v = stored_member_enumerator.Current.Value;
                    current = v;
                    // Try markup extension
                    // FIXME: is this rule correct?
                    if (!String.IsNullOrEmpty(v) && v [0] == '{')
                    {
                        var pai = ParsedMarkupExtensionInfo.Parse(v, xaml_namespace_resolver, sctx);
                        types.Push(pai.Type);
                        get_flags.Push(false);
                        current   = pai.Type;
                        node_type = XamlNodeType.StartObject;
                        markup_extension_attr_members = pai.Arguments.GetEnumerator();
                    }
                    else
                    {
                        node_type = XamlNodeType.Value;
                    }
                    return(true);

                case XamlNodeType.EndObject:                 // of MarkupExtension
                case XamlNodeType.Value:
                    // -> EndMember
                    current   = null;
                    node_type = XamlNodeType.EndMember;
                    return(true);
                }
            }

            stored_member_enumerator = null;
            return(false);
        }
        ParsedMarkupExtensionInfo ReadMarkup()
        {
            var info = new ParsedMarkupExtensionInfo(this);

            try {
                info.Parse();
                index += info.index;
                return(info);
            } catch {
            }
            return(null);
        }
Exemple #3
0
        // Note that it could return invalid (None) node to tell the caller that it is not really an object element.
        IEnumerable <XamlXmlNodeInfo> ReadObjectElement(XamlType parentType, XamlMember currentMember)
        {
            if (r.NodeType != XmlNodeType.Element)
            {
                //throw new XamlParseException (String.Format ("Element is expected, but got {0}", r.NodeType));
                yield return(Node(XamlNodeType.Value, r.Value));

                yield break;
            }

            if (r.MoveToFirstAttribute())
            {
                do
                {
                    if (r.NamespaceURI == XamlLanguage.Xmlns2000Namespace)
                    {
                        yield return(Node(XamlNodeType.NamespaceDeclaration, new NamespaceDeclaration(r.Value, r.Prefix == "xmlns" ? r.LocalName : String.Empty)));
                    }
                } while (r.MoveToNextAttribute());
                r.MoveToElement();
            }

            var sti = GetStartTagInfo();

            var xt = sctx.GetXamlType(sti.TypeName);

            if (xt == null)
            {
                // Current element could be for another member in the parent type (if exists)
                if (parentType != null && (r.LocalName.IndexOf('.') > 0 || parentType.GetMember(r.LocalName) != null))
                {
                    // stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
                    yield return(Node(XamlNodeType.None, null));

                    yield break;
                }

                // creates name-only XamlType. Also, it does not seem that it does not store this XamlType to XamlSchemaContext (Try GetXamlType(xtn) after reading such xaml node, it will return null).
                xt = new XamlType(sti.Namespace, sti.Name, sti.TypeName.TypeArguments == null ? null : sti.TypeName.TypeArguments.Select <XamlTypeName, XamlType> (xxtn => sctx.GetXamlType(xxtn)).ToArray(), sctx);
            }

            bool isGetObject = false;

            if (currentMember != null && !xt.CanAssignTo(currentMember.Type))
            {
                if (currentMember.DeclaringType != null && currentMember.DeclaringType.ContentProperty == currentMember)
                {
                    isGetObject = true;
                }

                // It could still be GetObject if current_member
                // is not a directive and current type is not
                // a markup extension.
                // (I'm not very sure about the condition;
                // it could be more complex.)
                // seealso: bug #682131
                else if (!(currentMember is XamlDirective) &&
                         !xt.IsMarkupExtension)
                {
                    isGetObject = true;
                }
            }

            if (isGetObject)
            {
                yield return(Node(XamlNodeType.GetObject, currentMember.Type));

                foreach (var ni in ReadMembers(parentType, currentMember.Type))
                {
                    yield return(ni);
                }
                yield return(Node(XamlNodeType.EndObject, currentMember.Type));

                yield break;
            }
            // else

            yield return(Node(XamlNodeType.StartObject, xt));

            // process attribute members (including MarkupExtensions)
            ProcessAttributesToMember(sctx, sti, xt);

            foreach (var pair in sti.Members)
            {
                yield return(Node(XamlNodeType.StartMember, pair.Key));

                // Try markup extension
                // FIXME: is this rule correct?
                var v = pair.Value;
                if (!String.IsNullOrEmpty(v) && v [0] == '{')
                {
                    var pai = ParsedMarkupExtensionInfo.Parse(v, xaml_namespace_resolver, sctx);
                    yield return(Node(XamlNodeType.StartObject, pai.Type));

                    foreach (var xepair in pai.Arguments)
                    {
                        yield return(Node(XamlNodeType.StartMember, xepair.Key));

                        if (xepair.Value is List <string> )
                        {
                            foreach (var s in (List <string>)xepair.Value)
                            {
                                yield return(Node(XamlNodeType.Value, s));
                            }
                        }
                        else
                        {
                            yield return(Node(XamlNodeType.Value, xepair.Value));
                        }
                        yield return(Node(XamlNodeType.EndMember, xepair.Key));
                    }
                    yield return(Node(XamlNodeType.EndObject, pai.Type));
                }
                else
                {
                    yield return(Node(XamlNodeType.Value, pair.Value));
                }

                yield return(Node(XamlNodeType.EndMember, pair.Key));
            }

            // process content members
            if (!r.IsEmptyElement)
            {
                r.Read();
                foreach (var ni in ReadMembers(parentType, xt))
                {
                    yield return(ni);
                }
                r.ReadEndElement();
            }
            else
            {
                r.Read();                  // consume empty element.
            }
            yield return(Node(XamlNodeType.EndObject, xt));
        }
Exemple #4
0
        // Note that it could return invalid (None) node to tell the caller that it is not really an object element.
        IEnumerable <XamlXmlNodeInfo> ReadObjectElement(XamlType parentType, XamlMember currentMember)
        {
            if (r.NodeType == XmlNodeType.Whitespace)
            {
                r.MoveToContent();
            }

            if (r.NodeType == XmlNodeType.EndElement)
            {
                yield break;
            }

            if (r.NodeType != XmlNodeType.Element)
            {
                throw new XamlParseException(String.Format("Element is expected, but got {0}", r.NodeType));
            }

            if (r.MoveToFirstAttribute())
            {
                do
                {
                    if (r.NamespaceURI == XamlLanguage.Xmlns2000Namespace)
                    {
                        yield return(Node(XamlNodeType.NamespaceDeclaration, new NamespaceDeclaration(ResolveLocalNamespace(r.Value), r.Prefix == "xmlns" ? r.LocalName : String.Empty)));
                    }
                } while (r.MoveToNextAttribute());
                r.MoveToElement();
            }

            var sti = GetStartTagInfo();

            var xt = sctx.GetXamlType(sti.TypeName);

            if (ReferenceEquals(xt, null))
            {
                // Current element could be for another member in the parent type (if exists)
                if (parentType != null && (r.LocalName.IndexOf('.') > 0 || parentType.GetMember(r.LocalName) != null))
                {
                    // stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
                    yield return(Node(XamlNodeType.None, null));

                    yield break;
                }

                // creates name-only XamlType. Also, it does not seem that it does not store this XamlType to XamlSchemaContext (Try GetXamlType(xtn) after reading such xaml node, it will return null).
                xt = new XamlType(sti.Namespace, sti.Name, sti.TypeName.TypeArguments?.Select(xxtn => sctx.GetXamlType(xxtn)).ToArray(), sctx);
            }

            // It could still be GetObject if current_member is not defer-loaded, it
            // is not a directive, and current type is not
            // a markup extension.
            // (I'm not very sure about the condition;
            // it could be more complex.)
            // seealso: bug #682131
            if (!ReferenceEquals(currentMember, null) &&
                ReferenceEquals(currentMember.DeferringLoader, null) &&
                !xt.CanAssignTo(currentMember.Type) &&
                !ReferenceEquals(xt, XamlLanguage.Reference) &&
                (
                    currentMember.DeclaringType?.ContentProperty == currentMember ||
                    (!currentMember.IsDirective && !xt.IsMarkupExtension)
                )
                )
            {
                yield return(Node(XamlNodeType.GetObject, currentMember.Type));

                foreach (var ni in ReadMembers(parentType, currentMember.Type))
                {
                    yield return(ni);
                }
                yield return(Node(XamlNodeType.EndObject, currentMember.Type));

                yield break;
            }


            yield return(Node(XamlNodeType.StartObject, xt));

            // process attribute members (including MarkupExtensions)
            ProcessAttributesToMember(sti, xt);

            for (int i = 0; i < sti.Members.Count; i++)
            {
                var memberInfo = sti.Members[i];
                yield return(Node(XamlNodeType.StartMember, memberInfo.Member, memberInfo.LineInfo));

                // Try markup extension
                // FIXME: is this rule correct?
                var v = memberInfo.Value;
                if (!string.IsNullOrEmpty(v) && v[0] == '{')
                {
                    if (v.Length >= 2 && v[1] == '}')
                    {
                        // escaped value with {} at the beginning of the string
                        yield return(Node(XamlNodeType.Value, v.Substring(2)));
                    }
                    else
                    {
                        var pai = new ParsedMarkupExtensionInfo(v, xaml_namespace_resolver, sctx);
                        pai.Parse();
                        foreach (var node in ReadMarkup(pai))
                        {
                            yield return(node);
                        }
                    }
                }
                else
                {
                    yield return(Node(XamlNodeType.Value, v, memberInfo.LineInfo));
                }

                yield return(Node(XamlNodeType.EndMember, memberInfo.Member, memberInfo.LineInfo));
            }

            // process content members
            if (!r.IsEmptyElement)
            {
                r.Read();
                foreach (var ni in ReadMembers(parentType, xt))
                {
                    yield return(ni);
                }
                r.ReadEndElement();
            }
            else
            {
                r.Read();                  // consume empty element.
            }
            yield return(Node(XamlNodeType.EndObject, xt));
        }