protected void Read_ListXmlSerializable (XamlReader r) { while (true) { r.Read (); if (r.Member == XamlLanguage.Items) break; if (r.IsEof) Assert.Fail ("Items did not appear"); } // t:XmlSerializable (yes...it is not XData!) Assert.IsTrue (r.Read (), "so#1-1"); Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2"); var xt = new XamlType (typeof (XmlSerializable), r.SchemaContext); Assert.AreEqual (xt, r.Type, "so#1-3"); // /t:XmlSerializable Assert.IsTrue (r.Read (), "eo#1-1"); Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2"); r.Close (); }
public void ProcessDefaultValue(XamlMember propertyValue, XamlReader subReader, IXamlLineInfo lineInfo) { XamlReader reader; bool flag = false; subReader.Read(); if (!subReader.Member.IsNameValid) { throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidXamlMember(subReader.Member.Name), lineInfo)); } this.nodes.Writer.WriteStartMember(propertyValue, lineInfo); subReader.Read(); if (subReader.NodeType == XamlNodeType.GetObject) { subReader.Read(); subReader.Read(); reader = subReader.ReadSubtree(); reader.Read(); } else { reader = subReader; } if ((reader.NodeType != XamlNodeType.EndMember) && (reader.NodeType != XamlNodeType.StartObject)) { flag = true; this.nodes.Writer.WriteStartObject(this.Type, lineInfo); this.nodes.Writer.WriteStartMember(XamlLanguage.Initialization, lineInfo); } while (!reader.IsEof) { this.nodes.Writer.WriteNode(reader, lineInfo); reader.Read(); } reader.Close(); if (!object.ReferenceEquals(reader, subReader)) { subReader.Read(); while (subReader.Read()) { this.nodes.Writer.WriteNode(subReader, lineInfo); } } if (flag) { this.nodes.Writer.WriteEndObject(lineInfo); this.nodes.Writer.WriteEndMember(lineInfo); } subReader.Close(); }
public void ProcessDefaultValue(XamlMember propertyValue, XamlReader subReader, IXamlLineInfo lineInfo) { bool addedStartObject = false; // 1) swap out the start member with <ActivityProperty.Value> subReader.Read(); if (!subReader.Member.IsNameValid) { throw FxTrace.Exception.AsError(CreateXamlException(SR.InvalidXamlMember(subReader.Member.Name), lineInfo)); } this.nodes.Writer.WriteStartMember(propertyValue, lineInfo); // temporary hack: read past GetObject/StartMember nodes that are added by // the XAML stack. This has been fixed in the WPF branch, but we haven't FI'ed that yet XamlReader valueReader; subReader.Read(); if (subReader.NodeType == XamlNodeType.GetObject) { subReader.Read(); subReader.Read(); valueReader = subReader.ReadSubtree(); valueReader.Read(); } else { valueReader = subReader; } // Add SO tag if necessary UNLESS there's no value to wrap (which means we're already at EO) if (valueReader.NodeType != XamlNodeType.EndMember && valueReader.NodeType != XamlNodeType.StartObject) { addedStartObject = true; // Add <TypeOfProperty> nodes so that type converters work correctly this.nodes.Writer.WriteStartObject(this.Type, lineInfo); this.nodes.Writer.WriteStartMember(XamlLanguage.Initialization, lineInfo); } // 3) copy over the value while (!valueReader.IsEof) { this.nodes.Writer.WriteNode(valueReader, lineInfo); valueReader.Read(); } valueReader.Close(); // 4) close up the extra nodes if (!object.ReferenceEquals(valueReader, subReader)) { subReader.Read(); while (subReader.Read()) { this.nodes.Writer.WriteNode(subReader, lineInfo); } } if (addedStartObject) { this.nodes.Writer.WriteEndObject(lineInfo); this.nodes.Writer.WriteEndMember(lineInfo); } subReader.Close(); }
public ActivityPropertyHolder(DynamicActivityXamlReader parent, XamlReader reader) { this.parent = parent; this.nodes = new XamlNodeQueue(parent.SchemaContext); IXamlLineInfo innerReaderLineInfo = parent.innerReaderLineInfo; reader.Read(); this.nodes.Writer.WriteStartObject(parent.activityPropertyXamlType, innerReaderLineInfo); int num = 1; int a = 0; int num3 = 0; bool flag = reader.Read(); while (flag) { XamlMember activityPropertyName; switch (reader.NodeType) { case XamlNodeType.StartObject: case XamlNodeType.GetObject: { num++; DynamicActivityXamlReader.IncrementIfPositive(ref a); DynamicActivityXamlReader.IncrementIfPositive(ref num3); if ((num3 <= 0) || !(reader.Type == parent.xamlTypeXamlType)) { goto Label_0231; } this.nodes.Writer.WriteStartObject(parent.typeXamlType, innerReaderLineInfo); flag = reader.Read(); continue; } case XamlNodeType.EndObject: { num--; if (num != 0) { goto Label_0213; } flag = reader.Read(); continue; } case XamlNodeType.StartMember: if (!(reader.Member.DeclaringType == XamlLanguage.Property)) { goto Label_0231; } activityPropertyName = reader.Member; if (!(activityPropertyName == DynamicActivityXamlReader.xPropertyName)) { break; } activityPropertyName = parent.activityPropertyName; if (a == 0) { a = 1; } goto Label_0115; case XamlNodeType.EndMember: DynamicActivityXamlReader.DecrementIfPositive(ref a); DynamicActivityXamlReader.DecrementIfPositive(ref num3); goto Label_0231; case XamlNodeType.Value: if (a != 1) { goto Label_014F; } this.Name = reader.Value as string; goto Label_0231; default: goto Label_0231; } if (activityPropertyName == DynamicActivityXamlReader.xPropertyType) { activityPropertyName = parent.activityPropertyType; if (num3 == 0) { num3 = 1; } } else { if (activityPropertyName != DynamicActivityXamlReader.xPropertyAttributes) { throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.PropertyMemberNotSupportedByActivityXamlServices(activityPropertyName.Name), innerReaderLineInfo)); } activityPropertyName = parent.activityPropertyAttributes; } Label_0115: this.nodes.Writer.WriteStartMember(activityPropertyName, innerReaderLineInfo); flag = reader.Read(); continue; Label_014F: if (num3 == 1) { XamlTypeName xamlTypeName = XamlTypeName.Parse(reader.Value as string, parent.namespaceTable); XamlType xamlType = parent.SchemaContext.GetXamlType(xamlTypeName); if (xamlType == null) { throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidPropertyType(reader.Value as string, this.Name), innerReaderLineInfo)); } this.Type = xamlType; } goto Label_0231; Label_0213: DynamicActivityXamlReader.DecrementIfPositive(ref a); DynamicActivityXamlReader.DecrementIfPositive(ref num3); Label_0231: this.nodes.Writer.WriteNode(reader, innerReaderLineInfo); flag = reader.Read(); } reader.Close(); }
public ActivityPropertyHolder(DynamicActivityXamlReader parent, XamlReader reader) { this.parent = parent; this.nodes = new XamlNodeQueue(parent.SchemaContext); IXamlLineInfo readerLineInfo = parent.innerReaderLineInfo; // parse the subtree, and extract out the Name and Type for now. // keep the node-list open for now, just in case a default value appears // later in the document // Rewrite "<x:Property>" to "<DynamicActivityProperty>" reader.Read(); this.nodes.Writer.WriteStartObject(parent.activityPropertyXamlType, readerLineInfo); int depth = 1; int nameDepth = 0; int typeDepth = 0; bool continueReading = reader.Read(); while (continueReading) { switch (reader.NodeType) { case XamlNodeType.StartMember: // map <x:Property> membes to the appropriate <DynamicActivity.Property> members if (reader.Member.DeclaringType == XamlLanguage.Property) { XamlMember mappedMember = reader.Member; if (mappedMember == xPropertyName) { mappedMember = parent.activityPropertyName; if (nameDepth == 0) { nameDepth = 1; } } else if (mappedMember == xPropertyType) { mappedMember = parent.activityPropertyType; if (typeDepth == 0) { typeDepth = 1; } } else if (mappedMember == xPropertyAttributes) { mappedMember = parent.activityPropertyAttributes; } else { throw FxTrace.Exception.AsError(CreateXamlException(SR.PropertyMemberNotSupportedByActivityXamlServices(mappedMember.Name), readerLineInfo)); } this.nodes.Writer.WriteStartMember(mappedMember, readerLineInfo); continueReading = reader.Read(); continue; } break; case XamlNodeType.Value: if (nameDepth == 1) { // We only support property name as an attribute (nameDepth == 1) this.Name = reader.Value as string; } else if (typeDepth == 1) { // We only support property type as an attribute (typeDepth == 1) XamlTypeName xamlTypeName = XamlTypeName.Parse(reader.Value as string, parent.namespaceTable); XamlType xamlType = parent.SchemaContext.GetXamlType(xamlTypeName); if (xamlType == null) { throw FxTrace.Exception.AsError(CreateXamlException(SR.InvalidPropertyType(reader.Value as string, this.Name), readerLineInfo)); } this.Type = xamlType; } break; case XamlNodeType.StartObject: case XamlNodeType.GetObject: depth++; IncrementIfPositive(ref nameDepth); IncrementIfPositive(ref typeDepth); if (typeDepth > 0 && reader.Type == parent.xamlTypeXamlType) { this.nodes.Writer.WriteStartObject(parent.typeXamlType, readerLineInfo); continueReading = reader.Read(); continue; } break; case XamlNodeType.EndObject: depth--; if (depth == 0) { continueReading = reader.Read(); continue; // skip this node, we'll close it by hand in CopyTo() } DecrementIfPositive(ref nameDepth); DecrementIfPositive(ref typeDepth); break; case XamlNodeType.EndMember: DecrementIfPositive(ref nameDepth); DecrementIfPositive(ref typeDepth); break; } // if we didn't continue (from a mapped case), just copy over this.nodes.Writer.WriteNode(reader, readerLineInfo); continueReading = reader.Read(); } reader.Close(); }