// This method is a workaround for TFS bug #788190, since XamlReader.ReadSubtree() should (but doesn't) preserve IXamlLineInfo on the subreader public static void Transform(XamlReader reader, XamlWriter writer, IXamlLineInfo readerLineInfo, bool closeWriter) { IXamlLineInfoConsumer consumer = writer as IXamlLineInfoConsumer; Fx.Assert(consumer != null && consumer.ShouldProvideLineInfo, "Should only call this function to write into a XamlNodeQueue.Writer, which is always IXamlLineInfoConsumer"); bool shouldPassLineNumberInfo = false; if (readerLineInfo != null) { shouldPassLineNumberInfo = true; } while (reader.Read()) { if (shouldPassLineNumberInfo) { consumer.SetLineInfo(readerLineInfo.LineNumber, readerLineInfo.LinePosition); } writer.WriteNode(reader); } if (closeWriter) { writer.Close(); } }
// Given the viewStateInfo dictionary, this method returns a xaml node list matching a ViewStateManager // object. static XamlNodeList CreateViewStateManagerNodeList(Dictionary <string, XamlNodeList> viewStateInfo, XamlSchemaContext schemaContext) { XamlNodeList viewStateManagerNodeList = new XamlNodeList(schemaContext); XamlMember viewStateDataMember = new XamlMember(typeof(ViewStateManager).GetProperty("ViewStateData"), schemaContext); XamlType viewStateManagerType = new XamlType(typeof(ViewStateManager), schemaContext); XamlType viewStateDataType = new XamlType(typeof(ViewStateData), schemaContext); XamlMember idMember = new XamlMember(typeof(ViewStateData).GetProperty("Id"), schemaContext); using (XamlWriter viewStateManagerNodeWriter = viewStateManagerNodeList.Writer) { viewStateManagerNodeWriter.WriteStartObject(viewStateManagerType); viewStateManagerNodeWriter.WriteStartMember(viewStateDataMember); viewStateManagerNodeWriter.WriteGetObject(); viewStateManagerNodeWriter.WriteStartMember(XamlLanguage.Items); foreach (KeyValuePair <string, XamlNodeList> entry in viewStateInfo) { viewStateManagerNodeWriter.WriteStartObject(viewStateDataType); viewStateManagerNodeWriter.WriteStartMember(idMember); viewStateManagerNodeWriter.WriteValue(entry.Key); viewStateManagerNodeWriter.WriteEndMember(); // idMember XamlReader viewStateValueReader = entry.Value.GetReader(); while (viewStateValueReader.Read()) { viewStateManagerNodeWriter.WriteNode(viewStateValueReader); } viewStateManagerNodeWriter.WriteEndObject(); // viewStateDataType } viewStateManagerNodeWriter.WriteEndMember(); // XamlLanguage.Items viewStateManagerNodeWriter.WriteEndObject(); // GetObject viewStateManagerNodeWriter.WriteEndMember(); // viewStateDataMember viewStateManagerNodeWriter.WriteEndObject(); // viewStateManagerType viewStateManagerNodeWriter.Close(); } return(viewStateManagerNodeList); }
private object DoStuffWithSkipper(SkipMode skipMode) { if (_removeType == null || _removeProperty == null) { throw new Exception("remove something is null"); } bool more = _mainReader.Read(); while (more) { bool skipped = false; switch (_mainReader.NodeType) { case XamlNodeType.StartObject: if (_mainReader.Type == _removeType) { Process(skipMode); skipped = true; } break; case XamlNodeType.StartMember: if (_mainReader.Member == _removeProperty) { Process(skipMode); skipped = true; } break; } if (!skipped) { _mainWriter.WriteNode(_mainReader); more = _mainReader.Read(); } } _mainWriter.Close(); XamlObjectWriter objectWriter = _mainWriter as XamlObjectWriter; return((objectWriter == null) ? null : objectWriter.Result); }
// -------------------------- protected override void Dispose(bool disposing) { try { if (disposing && !IsDisposed) { CurrentNodeText = "Closed."; BuildString(); if (_wrappedWriter != null) { _wrappedWriter.Close(); } } } finally { base.Dispose(disposing); } }
protected override void Dispose(bool disposing) { try { if (disposing && !IsDisposed) { Indent(); _out.WriteLine("Closed."); if (_wrappedWriter != null) { _wrappedWriter.Close(); } } } finally { base.Dispose(disposing); } }
public static void Transform(XamlReader reader, XamlWriter writer, IXamlLineInfo readerLineInfo, bool closeWriter) { IXamlLineInfoConsumer consumer = writer as IXamlLineInfoConsumer; bool flag = false; if (readerLineInfo != null) { flag = true; } while (reader.Read()) { if (flag) { consumer.SetLineInfo(readerLineInfo.LineNumber, readerLineInfo.LinePosition); } writer.WriteNode(reader); } if (closeWriter) { writer.Close(); } }
XamlNodeList RewriteRootNode(XamlNodeList strippedXamlNodes, string name, string @namespace) { // Rewrite the root node to have the name of class declared via x:Class (rather than the base class) // Also, for any properties on the root object that are declared in this class, need to rewrite the // namespace to include the root namespace, if there is one. string oldNamespace = null; if (!string.IsNullOrEmpty(this.rootNamespace)) { oldNamespace = @namespace; if (!string.IsNullOrEmpty(@namespace)) { @namespace = this.rootNamespace + "." + @namespace; } else { @namespace = this.rootNamespace; } } string namespaceName = string.Format(CultureInfo.InvariantCulture, "{0}{1};{2}{3}", XamlBuildTaskServices.ClrNamespaceUriNamespacePart, @namespace, XamlBuildTaskServices.ClrNamespaceUriAssemblyPart, this.localAssemblyName); XamlReader reader = strippedXamlNodes.GetReader(); XamlSchemaContext xsc = reader.SchemaContext; XamlNodeList newStrippedXamlNodes = new XamlNodeList(xsc); XamlWriter writer = newStrippedXamlNodes.Writer; int depth = 0; XamlType rootXamlType = null; while (reader.Read()) { switch (reader.NodeType) { case XamlNodeType.StartObject: case XamlNodeType.GetObject: depth++; break; case XamlNodeType.EndObject: depth--; break; } if (reader.NodeType == XamlNodeType.StartObject && depth == 1) { rootXamlType = new XamlType(namespaceName, name, null, xsc); writer.WriteStartObject(rootXamlType); } else if (reader.NodeType == XamlNodeType.StartMember && depth == 1 && reader.Member.IsUnknown && reader.Member.DeclaringType != null && reader.Member.DeclaringType.Name == rootXamlType.Name) { string clrNs; XamlMember member = reader.Member; if (XamlBuildTaskServices.TryExtractClrNs(member.PreferredXamlNamespace, out clrNs) && clrNs == oldNamespace) { // This is a member defined on the document root type, but missing the project root namespace. Fix it. XamlMember newMember = new XamlMember(member.Name, rootXamlType, member.IsAttachable); Fx.Assert(rootXamlType != null, "First StartObject should already have been processed"); writer.WriteStartMember(newMember); } else { writer.WriteNode(reader); } } else { writer.WriteNode(reader); } } writer.Close(); return(newStrippedXamlNodes); }