Exemplo n.º 1
0
 public void Push(SimpleWriterFrame frame)
 {
     _stackData[CurrentIndex++] = frame;
     if (CurrentIndex == _stackData.Length)
     {
         //double the size of the stack
         var newStackData = new SimpleWriterFrame[_stackData.Length * 2];
         _stackData.CopyTo(newStackData, 0);
         _stackData = newStackData;
     }
 }
Exemplo n.º 2
0
        public override void WriteNamespace(NamespaceDeclaration namespaceDeclaration)
        {
            var xamlNs = namespaceDeclaration.Namespace;
            var prefix = namespaceDeclaration.Prefix;

            Indent();
            var prefixString = string.IsNullOrEmpty(prefix) ? string.Empty : ":" + prefix;

            if (xamlNs == null)
            {
                _out.Write("NS  xmlns{0}={1}", prefixString, _nullString);
            }
            else
            {
                _out.Write("NS  xmlns{0}=\"{1}\"", prefixString, xamlNs);
            }
            _out.WriteLine("     {0}", LineInfoString);

            SimpleWriterFrame frame;

            if (_stack.CurrentIndex == 0)
            {
                frame = new SimpleWriterFrame();
                _stack.Push(frame);
            }
            else
            {
                frame = _stack.Peek();
                if (frame.NodeType == XamlNodeType.GetObject ||
                    frame.NodeType == XamlNodeType.StartObject)
                {
                    frame = new SimpleWriterFrame();
                    _stack.Push(frame);
                }
            }

            frame.NodeType = XamlNodeType.StartMember;
            frame.AddNamespaceTableEntry(xamlNs, prefix);

            if (_wrappedWriter != null)
            {
                _wrappedWriter.WriteNamespace(new NamespaceDeclaration(xamlNs, prefix));
            }
        }
Exemplo n.º 3
0
        private void WriteObject(XamlType xamlType, bool isFromMember)

        {
            Indent();

            if (isFromMember)
            {
                _out.Write("GO");
            }
            else
            {
                _out.Write("SO ");
            }

            SimpleWriterFrame frame;

            if (_stack.CurrentIndex == 0 ||
                _stack.Peek().NodeType == XamlNodeType.StartObject ||
                _stack.Peek().NodeType == XamlNodeType.GetObject)
            {
                frame = new SimpleWriterFrame();
                _stack.Push(frame);
            }
            else
            {
                frame = _stack.Peek();
            }

            frame.Type = xamlType;

            if (xamlType == null)
            {
                if (isFromMember)
                {
                    frame.NodeType = XamlNodeType.GetObject;
                }
                else
                {
                    _out.Write(_nullString);
                }
            }
            else
            {
                // Figure out prefix
                frame.NodeType = XamlNodeType.StartObject;
                var xmlNamespaces        = xamlType.GetXamlNamespaces();
                var prefix               = _stack.FindPrefixFromXmlnsList(xmlNamespaces);
                _stack.Peek().TypePrefix = prefix;

                switch (prefix)
                {
                case null:
                    var nullStr = isFromMember ? _nullObjectFromMember : _nullString;
                    _out.Write(nullStr + ":");
                    break;

                case "":
                    break;

                default:
                    _out.Write("{0}:", prefix);
                    break;
                }

                if (xamlType.TypeArguments != null)
                {
                    _out.Write("{0}({1})", xamlType.Name, Join(xamlType.TypeArguments, PrintType, ", "));
                }
                else
                {
                    _out.Write("{0}", xamlType.Name);
                }
            }

            if (!isFromMember && xamlType.IsUnknown)
            {
                _out.Write("     [{0}]", UnknownText);
            }

            _out.WriteLine("     {0}", LineInfoString);
            ++_depth;

            if (_wrappedWriter != null)
            {
                if (isFromMember)
                {
                    _wrappedWriter.WriteGetObject();
                }
                else
                {
                    _wrappedWriter.WriteStartObject(xamlType);
                }
            }
        }