protected void WriteReferencedElements() { if (referencedElements == null) { return; } if (callbacks == null) { return; } while (referencedElements.Count > 0) { object o = referencedElements.Dequeue(); TypeData td = TypeTranslator.GetTypeData(o.GetType()); WriteCallbackInfo info = (WriteCallbackInfo)callbacks[o.GetType()]; WriteStartElement(info.TypeName, info.TypeNs, true); Writer.WriteAttributeString("id", GetId(o, false)); if (td.SchemaType != SchemaTypes.Array) // Array use its own "arrayType" attribute { WriteXsiType(info.TypeName, info.TypeNs); } info.Callback(o); WriteEndElement(); } }
protected object ReadReferencedElement(string name, string ns) { XmlQualifiedName qname = GetXsiType(); if (qname == null) { qname = new XmlQualifiedName(name, ns); } string id = Reader.GetAttribute("id"); object ob; // it takes precedence over xsi:type. // Sometimes there are array types in WSDL, // which are not reflected in client proxies. // In SOAP messages, they are marked // soap-env:arrayType, so use it (this could coexist // with xsi:type, which indicates the type in WSDL). // See bug #79057. string arrayTypeVal = Reader.GetAttribute(arrayType, soapNS); if (qname == arrayQName || arrayTypeVal != null && arrayTypeVal.Length > 0) { CollectionFixup fixup = (collFixups != null) ? (CollectionFixup)collFixups[id] : null; if (ReadList(out ob)) { // List complete (does not contain references) if (fixup != null) { fixup.Callback(fixup.Collection, ob); collFixups.Remove(id); ob = fixup.Collection; } } else if (fixup != null) { fixup.CollectionItems = (object[])ob; ob = fixup.Collection; } } else { WriteCallbackInfo info = GetCallbackInfo(qname); if (info == null) { ob = ReadTypedPrimitive(qname, id != null); } else { ob = info.Callback(); } } AddTarget(id, ob); return(ob); }
protected void AddReadCallback(string name, string ns, Type type, XmlSerializationReadCallback read) { WriteCallbackInfo info = new WriteCallbackInfo(); info.Type = type; info.TypeName = name; info.TypeNs = ns; info.Callback = read; typesCallbacks = EnsureHashtable(typesCallbacks); typesCallbacks.Add(new XmlQualifiedName(name, ns), info); }
protected void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable) { if (o == null) { if (isNullable) { WriteNullTagEncoded(n, ns); } return; } WriteStartElement(n, ns, true); CheckReferenceQueue(); if (callbacks.ContainsKey(o.GetType())) { WriteCallbackInfo info = (WriteCallbackInfo)callbacks[o.GetType()]; if (o.GetType().IsEnum) { info.Callback(o); } else if (suppressReference) { Writer.WriteAttributeString("id", GetId(o, false)); if (ambientType != o.GetType()) { WriteXsiType(info.TypeName, info.TypeNs); } info.Callback(o); } else { if (!AlreadyQueued(o)) { referencedElements.Enqueue(o); } Writer.WriteAttributeString("href", "#" + GetId(o, true)); } } else { // Must be a primitive type TypeData td = TypeTranslator.GetTypeData(o.GetType()); if (td.SchemaType != SchemaTypes.Primitive) { throw new InvalidOperationException("Invalid type: " + o.GetType().FullName); } WriteXsiType(td.XmlType, XmlSchema.Namespace); Writer.WriteString(XmlCustomFormatter.ToXmlString(td, o)); } WriteEndElement(); }
protected void AddWriteCallback(Type type, string typeName, string typeNs, XmlSerializationWriteCallback callback) { WriteCallbackInfo info = new WriteCallbackInfo(); info.Type = type; info.TypeName = typeName; info.TypeNs = typeNs; info.Callback = callback; if (callbacks == null) { callbacks = new Hashtable(); } callbacks.Add(type, info); }
protected object ReadReferencedElement(string name, string ns) { XmlQualifiedName qname = GetXsiType(); if (qname == null) { qname = new XmlQualifiedName(name, ns); } string id = Reader.GetAttribute("id"); object ob; if (qname == arrayQName) { CollectionFixup fixup = (collFixups != null) ? (CollectionFixup)collFixups[id] : null; if (ReadList(out ob)) { // List complete (does not contain references) if (fixup != null) { fixup.Callback(fixup.Collection, ob); collFixups.Remove(id); ob = fixup.Collection; } } else if (fixup != null) { fixup.CollectionItems = (object[])ob; ob = fixup.Collection; } } else { WriteCallbackInfo info = GetCallbackInfo(qname); if (info == null) { ob = ReadTypedPrimitive(qname); } else { ob = info.Callback(); } } AddTarget(id, ob); return(ob); }
protected void AddReadCallback (string name, string ns, Type type, XmlSerializationReadCallback read) { WriteCallbackInfo info = new WriteCallbackInfo (); info.Type = type; info.TypeName = name; info.TypeNs = ns; info.Callback = read; typesCallbacks = EnsureHashtable (typesCallbacks); typesCallbacks.Add (new XmlQualifiedName (name, ns), info); }
protected void AddWriteCallback (Type type, string typeName, string typeNs, XmlSerializationWriteCallback callback) { WriteCallbackInfo info = new WriteCallbackInfo (); info.Type = type; info.TypeName = typeName; info.TypeNs = typeNs; info.Callback = callback; if (callbacks == null) callbacks = new Hashtable (); callbacks.Add (type, info); }
protected object ReadReferencingElement(string name, string ns, bool elementCanBeType, out string fixupReference) { if (ReadNull()) { fixupReference = null; return(null); } string refid = Reader.GetAttribute("href"); if (refid == string.Empty || refid == null) { fixupReference = null; XmlQualifiedName qname = GetXsiType(); if (qname == null) { qname = new XmlQualifiedName(name, ns); } string arrayTypeAttr = Reader.GetAttribute(arrayType, soapNS); if (qname == arrayQName || arrayTypeAttr != null) { delayedListFixups = EnsureHashtable(delayedListFixups); fixupReference = "__<" + (delayedFixupId++) + ">"; object items; ReadList(out items); delayedListFixups [fixupReference] = items; return(null); } else { WriteCallbackInfo info = GetCallbackInfo(qname); if (info == null) { return(ReadTypedPrimitive(qname, true)); } else { return(info.Callback()); } } } else { if (refid.StartsWith("#")) { refid = refid.Substring(1); } readCount++; Reader.Skip(); if (TargetReady(refid)) { fixupReference = null; return(GetTarget(refid)); } else { fixupReference = refid; return(null); } } }
bool ReadList(out object resultList) { string arrayTypeAttr = Reader.GetAttribute(arrayType, soapNS); if (arrayTypeAttr == null) { arrayTypeAttr = Reader.GetAttribute(arrayType, wsdlNS); } XmlQualifiedName qn = ToXmlQualifiedName(arrayTypeAttr); int i = qn.Name.LastIndexOf('['); string dim = qn.Name.Substring(i); string itemType = qn.Name.Substring(0, i); int count = Int32.Parse(dim.Substring(1, dim.Length - 2), CultureInfo.InvariantCulture); Array list; i = itemType.IndexOf('['); if (i == -1) { i = itemType.Length; } string baseType = itemType.Substring(0, i); string arrayTypeName; if (qn.Namespace == w3SchemaNS) { arrayTypeName = TypeTranslator.GetPrimitiveTypeData(baseType).Type.FullName + itemType.Substring(i); } else { WriteCallbackInfo info = GetCallbackInfo(new XmlQualifiedName(baseType, qn.Namespace)); arrayTypeName = info.Type.FullName + itemType.Substring(i) + ", " + info.Type.Assembly.FullName; } list = Array.CreateInstance(Type.GetType(arrayTypeName), count); bool listComplete = true; if (Reader.IsEmptyElement) { readCount++; Reader.Skip(); } else { Reader.ReadStartElement(); for (int n = 0; n < count; n++) { whileIterationCount++; readCount++; Reader.MoveToContent(); string id; object item = ReadReferencingElement(itemType, qn.Namespace, out id); if (id == null) { list.SetValue(item, n); } else { AddFixup(new CollectionItemFixup(list, n, id)); listComplete = false; } } whileIterationCount = 0; Reader.ReadEndElement(); } resultList = list; return(listComplete); }