public bool ProcessNode(XamlReader reader, XamlWriter targetWriter, int currentDepth, IXamlLineInfo readerLineInfo) { if ((currentDepth == this.Depth) && ((reader.NodeType == XamlNodeType.NamespaceDeclaration) || (reader.NodeType == XamlNodeType.None))) { this.bufferedNodes.Writer.WriteNode(reader, readerLineInfo); reader.Read(); return(true); } if ((((reader.NodeType == XamlNodeType.StartObject) && reader.Type.IsGeneric) && ((reader.Type.UnderlyingType != null) && (reader.Type.Name == "PropertyReferenceExtension"))) && (reader.Type.UnderlyingType.GetGenericTypeDefinition() == typeof(PropertyReferenceExtension <>))) { if (this.bufferedNodes.Count > 0) { XamlServices.Transform(this.bufferedNodes.Reader, targetWriter, false); this.bufferedNodes = null; } XamlType type = reader.Type; XamlReader reader2 = reader.ReadSubtree(); XamlType xamlType = reader.SchemaContext.GetXamlType(typeof(ActivityBuilder)); XamlType type3 = reader.SchemaContext.GetXamlType(typeof(ActivityPropertyReference)); targetWriter.WriteStartMember(xamlType.GetAttachableMember("PropertyReference"), readerLineInfo); reader2.Read(); targetWriter.WriteStartObject(type3, readerLineInfo); targetWriter.WriteStartMember(type3.GetMember("TargetProperty"), readerLineInfo); targetWriter.WriteValue(this.currentMember.Name, readerLineInfo); targetWriter.WriteEndMember(readerLineInfo); bool flag = reader2.Read(); bool flag2 = false; while (flag) { if (((reader2.NodeType == XamlNodeType.StartMember) && (reader2.Member.DeclaringType == type)) && (reader2.Member.Name == "PropertyName")) { flag2 = true; } else if (flag2) { if (reader2.NodeType == XamlNodeType.EndMember) { flag2 = false; } else if (reader2.NodeType == XamlNodeType.Value) { targetWriter.WriteStartMember(type3.GetMember("SourceProperty"), readerLineInfo); targetWriter.WriteValue((string)reader2.Value, readerLineInfo); targetWriter.WriteEndMember(readerLineInfo); } } flag = reader2.Read(); } targetWriter.WriteEndObject(readerLineInfo); targetWriter.WriteEndMember(readerLineInfo); this.ExitObject = true; reader2.Close(); } else { this.FlushBuffer(targetWriter); targetWriter.WriteNode(reader, readerLineInfo); } return(false); }
// 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); }
public override void WriteStartObject(XamlType type) { CurrentNodeText = String.Format("SO {0}", type.Name); BuildString(); _indent += 1; if (_wrappedWriter != null) { _wrappedWriter.WriteStartObject(type); } }
} // proc WriteStartObject /// <summary>Start to write a xaml-object.</summary> /// <param name="xamlType"></param> /// <returns></returns> public XamlType WriteStartObject(XamlType xamlType) { xamlTypes.Push(xamlType); // write pending elements WritePendingStartItems(); WritePendingText(true); writer.WriteStartObject(xamlType); return(xamlType); } // proc WriteStartObject
internal static void WriteNodeList(XamlWriter writer, XamlNodeList nodeList) { // We need to pass the ErrorNodes contents through as a NodeList, because XOW doesn't // currently support unknown types, even inside a DeferLoad block. // But if a NodeList is written to XOW as a Value, XOW will unpack, forcing us to re-buffer // the nodes in our deferring loader. So we wrap the NodeList value inside a dummy StartObject. writer.WriteStartObject(XamlLanguage.Object); writer.WriteStartMember(XamlLanguage.Initialization); writer.WriteValue(nodeList); writer.WriteEndMember(); writer.WriteEndObject(); }
public override void WriteTo(XamlWriter writer) { Log("StartObject {0}", this.Type); writer.WriteStartObject(this.Type); Debug.Indent(); foreach (XamlNode node in this.Children) { node.WriteTo(writer); } Debug.Unindent(); Log("EndObject"); writer.WriteEndObject(); }
void WritestrippedXamlNode(XamlReader reader, XamlWriter writer) { switch (reader.NodeType) { case XamlNodeType.StartObject: XamlType xamlType = reader.Type; if (xamlType.IsUnknown) { IList <XamlType> typeArgs = UpdateTypeArgs(xamlType.TypeArguments, reader.SchemaContext); string xmlns = XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(xamlType.PreferredXamlNamespace, this.localAssemblyName); xamlType = new XamlType(xmlns, xamlType.Name, typeArgs, reader.SchemaContext); } writer.WriteStartObject(xamlType); break; case XamlNodeType.StartMember: XamlMember member = reader.Member; if (member.IsUnknown && !member.IsDirective) { string xmlns = XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(member.DeclaringType.PreferredXamlNamespace, this.localAssemblyName); XamlType memberXamlType = new XamlType(xmlns, member.DeclaringType.Name, member.DeclaringType.TypeArguments, reader.SchemaContext); member = new XamlMember(member.Name, memberXamlType, member.IsAttachable); } writer.WriteStartMember(member); break; case XamlNodeType.NamespaceDeclaration: NamespaceDeclaration ns = new NamespaceDeclaration( XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(reader.Namespace.Namespace, this.localAssemblyName), reader.Namespace.Prefix); writer.WriteNamespace(ns); break; case XamlNodeType.GetObject: case XamlNodeType.EndObject: case XamlNodeType.EndMember: case XamlNodeType.Value: case XamlNodeType.None: writer.WriteNode(reader); break; default: Debug.Fail("Unrecognized XamlNodeType value" + reader.NodeType.ToString()); break; } }
public static void WriteStartObject(this XamlWriter writer, XamlType type, IXamlLineInfo lineInfo) { PropagateLineInfo(writer, lineInfo); writer.WriteStartObject(type); }
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); }
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); } } }