예제 #1
0
        private void Visit(XamlXmlReader reader, XamlObjectDefinition xamlObject)
        {
            while (reader.Read())
            {
                WriteState(reader);

                switch (reader.NodeType)
                {
                case XamlNodeType.StartMember:
                    _depth++;
                    xamlObject.Members.Add(VisitMember(reader, xamlObject));
                    break;

                case XamlNodeType.StartObject:
                    _depth++;
                    xamlObject.Objects.Add(VisitObject(reader, xamlObject));
                    break;

                case XamlNodeType.Value:
                    xamlObject.Value = reader.Value;
                    break;

                case XamlNodeType.EndObject:
                    _depth--;
                    return;

                case XamlNodeType.EndMember:
                    _depth--;
                    break;

                default:
                    throw new InvalidOperationException();
                }
            }
        }
예제 #2
0
        private XamlObjectDefinition VisitObject(XamlXmlReader reader, XamlObjectDefinition owner)
        {
            var xamlObject = new XamlObjectDefinition(reader.Type, reader.LineNumber, reader.LinePosition, owner);

            Visit(reader, xamlObject);

            return(xamlObject);
        }
예제 #3
0
 public XamlObjectDefinition(XamlType type, int lineNumber, int linePosition, XamlObjectDefinition owner)
 {
     LineNumber   = lineNumber;
     LinePosition = linePosition;
     _type        = type;
     Owner        = owner;
     Members      = new List <XamlMemberDefinition>();
     Objects      = new List <XamlObjectDefinition>();
 }
예제 #4
0
        private XamlMemberDefinition VisitMember(XamlXmlReader reader, XamlObjectDefinition owner)
        {
            var member = new XamlMemberDefinition(reader.Member, reader.LineNumber, reader.LinePosition, owner);

            while (reader.Read())
            {
                WriteState(reader);

                switch (reader.NodeType)
                {
                case XamlNodeType.EndMember:
                    _depth--;
                    return(member);

                case XamlNodeType.Value:
                    if (IsLiteralInlineText(reader.Value, member, owner))
                    {
                        var run = ConvertLiteralInlineTextToRun(reader);
                        member.Objects.Add(run);
                    }
                    else
                    {
                        if (member.Value is string s)
                        {
                            member.Value += ", " + reader.Value;
                        }
                        else
                        {
                            member.Value = reader.Value;
                        }
                    }
                    break;

                case XamlNodeType.StartObject:
                    _depth++;
                    member.Objects.Add(VisitObject(reader, owner));
                    break;

                case XamlNodeType.EndObject:
                    _depth--;
                    break;

                case XamlNodeType.NamespaceDeclaration:
                    // Skip
                    break;

                default:
                    throw new InvalidOperationException("Unable to process {2} node at Line {0}, position {1}".InvariantCultureFormat(reader.LineNumber, reader.LinePosition, reader.NodeType));
                }
            }

            return(member);
        }
예제 #5
0
        private void BuildResourceMap(XamlObjectDefinition parentNode, XamlGlobalStaticResourcesMap map)
        {
            var contentNode = parentNode.Members.FirstOrDefault(m => m.Member.Name == "_UnknownContent");

            if (contentNode != null)
            {
                foreach (var resource in contentNode.Objects)
                {
                    var key = resource.Members.FirstOrDefault(m => m.Member.Name == "Key");

                    if (key != null)
                    {
                        map.Add(key.Value.ToString(), _defaultNamespace, XamlGlobalStaticResourcesMap.ResourcePrecedence.Local);
                    }
                }
            }
        }
예제 #6
0
        public XamlMemberDefinition(XamlMember xamlMember, int lineNumber, int linePosition, XamlObjectDefinition owner = null)
        {
            // TODO: Complete member initialization

            // If the DeclaringType is not properly resolved, we assume it should be the owner (xamlObject)
            if (xamlMember.DeclaringType == null &&
                owner != null &&
                xamlMember.PreferredXamlNamespace != XamlConstants.XamlXmlNamespace)            // e.g., x:Class, x:Name
            {
                xamlMember = XamlMember.WithDeclaringType(xamlMember, owner.Type);
            }

            this._xamlMember = xamlMember;
            LineNumber       = lineNumber;
            LinePosition     = linePosition;
            Objects          = new List <XamlObjectDefinition>();
            Owner            = owner;
        }
예제 #7
0
 private bool IsLiteralInlineText(object value, XamlMemberDefinition member, XamlObjectDefinition xamlObject)
 {
     return(value is string &&
            xamlObject.Type.Name == "TextBlock" &&
            (member.Member.Name == "_UnknownContent" || member.Member.Name == "Inlines"));
 }