2 // System.Xml.Serialization.XmlSerializationWriter.cs
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // Copyright (C) Tim Coleman, 2002
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Collections.Generic;
35 using System.Globalization;
38 using System.Xml.Schema;
39 using System.Runtime.Serialization;
40 using System.Reflection;
42 namespace System.Xml.Serialization
44 public abstract class XmlSerializationWriter
46 : XmlSerializationGeneratedCode
52 ObjectIDGenerator idGenerator;
54 bool topLevelElement = false;
59 Queue<object> referencedElements;
61 Queue referencedElements;
64 Hashtable serializedObjects;
65 const string xmlNamespace = "http://www.w3.org/2000/xmlns/";
66 const string unexpectedTypeError = "The type {0} was not expected. Use the" +
67 " XmlInclude or SoapInclude attribute to specify types that are not known statically.";
73 protected XmlSerializationWriter ()
76 serializedObjects = new Hashtable ();
79 internal void Initialize (XmlWriter writer, XmlSerializerNamespaces nss)
84 namespaces = new ArrayList ();
85 foreach (XmlQualifiedName ns in nss.ToArray())
86 if (ns.Name != "" && ns.Namespace != "")
91 #endregion // Constructors
96 protected IList XmlNamespaces {
97 get { return namespaces; }
98 set { namespaces = (value as ArrayList); }
101 protected ArrayList Namespaces {
102 get { return namespaces; }
103 set { namespaces = value; }
107 protected XmlWriter Writer {
108 get { return writer; }
109 set { writer = value; }
112 #endregion // Properties
116 protected void AddWriteCallback (Type type, string typeName, string typeNs, XmlSerializationWriteCallback callback)
118 WriteCallbackInfo info = new WriteCallbackInfo ();
120 info.TypeName = typeName;
121 info.TypeNs = typeNs;
122 info.Callback = callback;
124 if (callbacks == null) callbacks = new Hashtable ();
125 callbacks.Add (type, info);
128 protected Exception CreateChoiceIdentifierValueException (string value, string identifier, string name, string ns)
130 string message = string.Format ("Value '{0}' of the choice"
131 + " identifier '{1}' does not match element '{2}'"
132 + " from namespace '{3}'.", value, identifier,
134 return new InvalidOperationException (message);
137 protected Exception CreateInvalidChoiceIdentifierValueException (string type, string identifier)
139 string message = string.Format ("Invalid or missing choice"
140 + " identifier '{0}' of type '{1}'.", identifier,
142 return new InvalidOperationException (message);
145 protected Exception CreateMismatchChoiceException (string value, string elementName, string enumValue)
147 string message = String.Format ("Value of {0} mismatches the type of {1}, you need to set it to {2}.", elementName, value, enumValue);
148 return new InvalidOperationException (message);
151 protected Exception CreateUnknownAnyElementException (string name, string ns)
153 string message = String.Format ("The XML element named '{0}' from namespace '{1}' was not expected. The XML element name and namespace must match those provided via XmlAnyElementAttribute(s).", name, ns);
154 return new InvalidOperationException (message);
157 protected Exception CreateUnknownTypeException (object o)
159 return CreateUnknownTypeException (o.GetType ());
162 protected Exception CreateUnknownTypeException (Type type)
164 string message = String.Format ("The type {0} may not be used in this context.", type);
165 return new InvalidOperationException (message);
168 protected static byte[] FromByteArrayBase64 (byte[] value)
173 protected static string FromByteArrayHex (byte[] value)
175 return XmlCustomFormatter.FromByteArrayHex (value);
178 protected static string FromChar (char value)
180 return XmlCustomFormatter.FromChar (value);
183 protected static string FromDate (DateTime value)
185 return XmlCustomFormatter.FromDate (value);
188 protected static string FromDateTime (DateTime value)
190 return XmlCustomFormatter.FromDateTime (value);
193 protected static string FromEnum (long value, string[] values, long[] ids)
195 return XmlCustomFormatter.FromEnum (value, values, ids);
198 protected static string FromTime (DateTime value)
200 return XmlCustomFormatter.FromTime (value);
203 protected static string FromXmlName (string name)
205 return XmlCustomFormatter.FromXmlName (name);
208 protected static string FromXmlNCName (string ncName)
210 return XmlCustomFormatter.FromXmlNCName (ncName);
213 protected static string FromXmlNmToken (string nmToken)
215 return XmlCustomFormatter.FromXmlNmToken (nmToken);
218 protected static string FromXmlNmTokens (string nmTokens)
220 return XmlCustomFormatter.FromXmlNmTokens (nmTokens);
223 protected string FromXmlQualifiedName (XmlQualifiedName xmlQualifiedName)
225 if (xmlQualifiedName == null || xmlQualifiedName == XmlQualifiedName.Empty)
228 return GetQualifiedName (xmlQualifiedName.Name, xmlQualifiedName.Namespace);
231 private string GetId (object o, bool addToReferencesList)
233 if (idGenerator == null) idGenerator = new ObjectIDGenerator ();
236 long lid = idGenerator.GetId (o, out firstTime);
237 return String.Format (CultureInfo.InvariantCulture, "id{0}", lid);
241 bool AlreadyQueued (object ob)
243 if (idGenerator == null) return false;
246 idGenerator.HasId (ob, out firstTime);
250 private string GetNamespacePrefix (string ns)
252 string prefix = Writer.LookupPrefix (ns);
255 prefix = String.Format (CultureInfo.InvariantCulture, "q{0}", ++qnameCount);
256 WriteAttribute ("xmlns", prefix, null, ns);
261 private string GetQualifiedName (string name, string ns)
263 if (ns == String.Empty) return name;
265 string prefix = GetNamespacePrefix (ns);
266 if (prefix == String.Empty)
269 return String.Format ("{0}:{1}", prefix, name);
272 protected abstract void InitCallbacks ();
274 protected void TopLevelElement ()
276 topLevelElement = true;
279 protected void WriteAttribute (string localName, byte[] value)
281 WriteAttribute (localName, String.Empty, value);
284 protected void WriteAttribute (string localName, string value)
286 WriteAttribute (String.Empty, localName, String.Empty, value);
289 protected void WriteAttribute (string localName, string ns, byte[] value)
294 Writer.WriteStartAttribute (localName, ns);
296 Writer.WriteEndAttribute ();
299 protected void WriteAttribute (string localName, string ns, string value)
301 WriteAttribute (null, localName, ns, value);
304 protected void WriteAttribute (string prefix, string localName, string ns, string value)
309 Writer.WriteAttributeString (prefix, localName, ns, value);
313 void WriteXmlNode (XmlNode node)
315 if (node is XmlDocument)
316 node = ((XmlDocument) node).DocumentElement;
318 node.WriteTo (Writer);
321 protected void WriteElementEncoded (XmlNode node, string name, string ns, bool isNullable, bool any)
323 if (name != string.Empty)
328 WriteNullTagEncoded (name, ns);
332 Writer.WriteStartElement (name, ns);
334 Writer.WriteEndElement ();
341 protected void WriteElementLiteral (XmlNode node, string name, string ns, bool isNullable, bool any)
343 if (name != string.Empty)
348 WriteNullTagLiteral (name, ns);
352 Writer.WriteStartElement (name, ns);
354 Writer.WriteEndElement ();
362 protected void WriteElementQualifiedName (string localName, XmlQualifiedName value)
364 WriteElementQualifiedName (localName, String.Empty, value, null);
367 protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value)
369 WriteElementQualifiedName (localName, ns, value, null);
372 protected void WriteElementQualifiedName (string localName, XmlQualifiedName value, XmlQualifiedName xsiType)
374 WriteElementQualifiedName (localName, String.Empty, value, xsiType);
377 protected void WriteElementQualifiedName (string localName, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
379 localName = XmlCustomFormatter.FromXmlNCName (localName);
380 WriteStartElement (localName, ns);
381 if (xsiType != null) WriteXsiType (xsiType.Name, xsiType.Namespace);
382 Writer.WriteString (FromXmlQualifiedName (value));
386 protected void WriteElementString (string localName, string value)
388 WriteElementString (localName, String.Empty, value, null);
391 protected void WriteElementString (string localName, string ns, string value)
393 WriteElementString (localName, ns, value, null);
396 protected void WriteElementString (string localName, string value, XmlQualifiedName xsiType)
398 WriteElementString (localName, String.Empty, value, xsiType);
401 protected void WriteElementString (string localName, string ns, string value, XmlQualifiedName xsiType)
403 if (value == null) return;
405 if (xsiType != null) {
406 localName = XmlCustomFormatter.FromXmlNCName (localName);
407 WriteStartElement (localName, ns);
408 WriteXsiType (xsiType.Name, xsiType.Namespace);
409 Writer.WriteString (value);
413 Writer.WriteElementString (localName, ns, value);
416 protected void WriteElementStringRaw (string localName, byte[] value)
418 WriteElementStringRaw (localName, String.Empty, value, null);
421 protected void WriteElementStringRaw (string localName, string value)
423 WriteElementStringRaw (localName, String.Empty, value, null);
426 protected void WriteElementStringRaw (string localName, byte[] value, XmlQualifiedName xsiType)
428 WriteElementStringRaw (localName, String.Empty, value, xsiType);
431 protected void WriteElementStringRaw (string localName, string ns, byte[] value)
433 WriteElementStringRaw (localName, ns, value, null);
436 protected void WriteElementStringRaw (string localName, string ns, string value)
438 WriteElementStringRaw (localName, ns, value, null);
441 protected void WriteElementStringRaw (string localName, string value, XmlQualifiedName xsiType)
443 WriteElementStringRaw (localName, String.Empty, value, null);
446 protected void WriteElementStringRaw (string localName, string ns, byte[] value, XmlQualifiedName xsiType)
451 WriteStartElement (localName, ns);
454 WriteXsiType (xsiType.Name, xsiType.Namespace);
456 if (value.Length > 0)
457 Writer.WriteBase64(value,0,value.Length);
461 protected void WriteElementStringRaw (string localName, string ns, string value, XmlQualifiedName xsiType)
463 localName = XmlCustomFormatter.FromXmlNCName (localName);
464 WriteStartElement (localName, ns);
467 WriteXsiType (xsiType.Name, xsiType.Namespace);
469 Writer.WriteRaw (value);
473 protected void WriteEmptyTag (string name)
475 WriteEmptyTag (name, String.Empty);
478 protected void WriteEmptyTag (string name, string ns)
480 name = XmlCustomFormatter.FromXmlName (name);
481 WriteStartElement (name, ns);
485 protected void WriteEndElement ()
487 WriteEndElement (null);
490 protected void WriteEndElement (object o)
493 serializedObjects.Remove (o);
495 Writer.WriteEndElement ();
498 protected void WriteId (object o)
500 WriteAttribute ("id", GetId (o, true));
503 protected void WriteNamespaceDeclarations (XmlSerializerNamespaces xmlns)
508 IEnumerable<XmlQualifiedName> namespaces = ns.GetNamespaces ();
510 ICollection namespaces = xmlns.Namespaces.Values;
512 foreach (XmlQualifiedName qn in namespaces) {
513 if (qn.Namespace != String.Empty && Writer.LookupPrefix (qn.Namespace) != qn.Name)
514 WriteAttribute ("xmlns", qn.Name, xmlNamespace, qn.Namespace);
518 protected void WriteNullableQualifiedNameEncoded (string name, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
521 WriteElementQualifiedName (name, ns, value, xsiType);
523 WriteNullTagEncoded (name, ns);
526 protected void WriteNullableQualifiedNameLiteral (string name, string ns, XmlQualifiedName value)
529 WriteElementQualifiedName (name, ns, value);
531 WriteNullTagLiteral (name, ns);
534 protected void WriteNullableStringEncoded (string name, string ns, string value, XmlQualifiedName xsiType)
537 WriteElementString (name, ns, value, xsiType);
539 WriteNullTagEncoded (name, ns);
542 protected void WriteNullableStringEncodedRaw (string name, string ns, byte[] value, XmlQualifiedName xsiType)
545 WriteNullTagEncoded (name, ns);
547 WriteElementStringRaw (name, ns, value, xsiType);
550 protected void WriteNullableStringEncodedRaw (string name, string ns, string value, XmlQualifiedName xsiType)
553 WriteNullTagEncoded (name, ns);
555 WriteElementStringRaw (name, ns, value, xsiType);
558 protected void WriteNullableStringLiteral (string name, string ns, string value)
561 WriteElementString (name, ns, value, null);
563 WriteNullTagLiteral (name, ns);
566 protected void WriteNullableStringLiteralRaw (string name, string ns, byte[] value)
569 WriteNullTagLiteral (name, ns);
571 WriteElementStringRaw (name, ns, value);
574 protected void WriteNullableStringLiteralRaw (string name, string ns, string value)
577 WriteNullTagLiteral (name, ns);
579 WriteElementStringRaw (name, ns, value);
582 protected void WriteNullTagEncoded (string name)
584 WriteNullTagEncoded (name, String.Empty);
587 protected void WriteNullTagEncoded (string name, string ns)
589 Writer.WriteStartElement (name, ns);
590 Writer.WriteAttributeString ("nil", XmlSchema.InstanceNamespace, "true");
591 Writer.WriteEndElement ();
594 protected void WriteNullTagLiteral (string name)
596 WriteNullTagLiteral (name, String.Empty);
599 protected void WriteNullTagLiteral (string name, string ns)
601 WriteStartElement (name, ns);
602 Writer.WriteAttributeString ("nil", XmlSchema.InstanceNamespace, "true");
606 protected void WritePotentiallyReferencingElement (string n, string ns, object o)
608 WritePotentiallyReferencingElement (n, ns, o, null, false, false);
611 protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType)
613 WritePotentiallyReferencingElement (n, ns, o, ambientType, false, false);
616 protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference)
618 WritePotentiallyReferencingElement (n, ns, o, ambientType, suppressReference, false);
621 protected void WritePotentiallyReferencingElement (string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
625 if (isNullable) WriteNullTagEncoded (n, ns);
629 var t = o.GetType ();
631 WriteStartElement (n, ns, true);
633 CheckReferenceQueue ();
635 if (callbacks != null && callbacks.ContainsKey (o.GetType ()))
637 WriteCallbackInfo info = (WriteCallbackInfo) callbacks[t];
641 else if (suppressReference) {
642 Writer.WriteAttributeString ("id", GetId (o, false));
643 if (ambientType != t) WriteXsiType(info.TypeName, info.TypeNs);
647 if (!AlreadyQueued (o)) referencedElements.Enqueue (o);
648 Writer.WriteAttributeString ("href", "#" + GetId (o, true));
653 // Must be a primitive type or array of primitives
654 TypeData td = TypeTranslator.GetTypeData (t, null, true);
655 if (td.SchemaType == SchemaTypes.Primitive) {
656 if (t != ambientType)
657 WriteXsiType (td.XmlType, XmlSchema.Namespace);
658 Writer.WriteString (XmlCustomFormatter.ToXmlString (td, o));
659 } else if (IsPrimitiveArray (td)) {
660 if (!AlreadyQueued (o)) referencedElements.Enqueue (o);
661 Writer.WriteAttributeString ("href", "#" + GetId (o, true));
663 throw new InvalidOperationException ("Invalid type: " + t.FullName);
670 protected void WriteReferencedElements ()
672 if (referencedElements == null) return;
673 if (callbacks == null) return;
675 while (referencedElements.Count > 0)
677 object o = referencedElements.Dequeue ();
678 TypeData td = TypeTranslator.GetTypeData (o.GetType ());
679 WriteCallbackInfo info = (WriteCallbackInfo) callbacks[o.GetType()];
682 WriteStartElement (info.TypeName, info.TypeNs, true);
683 Writer.WriteAttributeString ("id", GetId (o, false));
685 if (td.SchemaType != SchemaTypes.Array) // Array use its own "arrayType" attribute
686 WriteXsiType(info.TypeName, info.TypeNs);
690 } else if (IsPrimitiveArray (td)) {
696 bool IsPrimitiveArray (TypeData td)
698 if (td.SchemaType == SchemaTypes.Array) {
699 if (td.ListItemTypeData.SchemaType == SchemaTypes.Primitive || td.ListItemType == typeof(object))
701 return IsPrimitiveArray (td.ListItemTypeData);
706 void WriteArray (object o, TypeData td)
708 TypeData itemTypeData = td;
713 itemTypeData = itemTypeData.ListItemTypeData;
714 xmlType = itemTypeData.XmlType;
717 while (itemTypeData.SchemaType == SchemaTypes.Array );
722 WriteStartElement("Array", XmlSerializer.EncodingNamespace, true);
723 Writer.WriteAttributeString("id", GetId(o, false));
724 if (td.SchemaType == SchemaTypes.Array) {
727 Writer.WriteAttributeString("arrayType", XmlSerializer.EncodingNamespace, GetQualifiedName(xmlType, XmlSchema.Namespace) + "[" + len.ToString() + "]");
728 for (int i = 0; i < len; i++) {
729 WritePotentiallyReferencingElement("Item", "", a.GetValue(i), td.ListItemType, false, true);
736 protected void WriteReferencingElement (string n, string ns, object o)
738 WriteReferencingElement (n, ns, o, false);
741 protected void WriteReferencingElement (string n, string ns, object o, bool isNullable)
745 if (isNullable) WriteNullTagEncoded (n, ns);
750 CheckReferenceQueue ();
751 if (!AlreadyQueued (o)) referencedElements.Enqueue (o);
753 Writer.WriteStartElement (n, ns);
754 Writer.WriteAttributeString ("href", "#" + GetId (o, true));
755 Writer.WriteEndElement ();
759 void CheckReferenceQueue ()
761 if (referencedElements == null)
764 referencedElements = new Queue<object> ();
766 referencedElements = new Queue ();
773 protected void WriteRpcResult (string name, string ns)
775 throw new NotImplementedException ();
778 protected void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable)
780 WriteSerializable (serializable, name, ns, isNullable, true);
786 void WriteSerializable (IXmlSerializable serializable, string name, string ns, bool isNullable, bool wrapped)
788 if (serializable == null)
790 if (isNullable && wrapped) WriteNullTagLiteral (name, ns);
796 Writer.WriteStartElement (name, ns);
797 serializable.WriteXml (Writer);
799 Writer.WriteEndElement ();
803 protected void WriteStartDocument ()
805 if (Writer.WriteState == WriteState.Start)
806 Writer.WriteStartDocument ();
809 protected void WriteStartElement (string name)
811 WriteStartElement (name, String.Empty, null, false);
814 protected void WriteStartElement (string name, string ns)
816 WriteStartElement (name, ns, null, false);
819 protected void WriteStartElement (string name, string ns, bool writePrefixed)
821 WriteStartElement (name, ns, null, writePrefixed);
824 protected void WriteStartElement (string name, string ns, object o)
826 WriteStartElement (name, ns, o, false);
829 protected void WriteStartElement (string name, string ns, object o, bool writePrefixed)
831 WriteStartElement (name, ns, o, writePrefixed, namespaces);
835 protected void WriteStartElement (string name, string ns, Object o, bool writePrefixed, XmlSerializerNamespaces xmlns)
837 WriteStartElement (name, ns, o, writePrefixed, xmlns != null ? xmlns.ToArray () : null);
841 void WriteStartElement (string name, string ns, object o, bool writePrefixed, ICollection namespaces)
845 if (serializedObjects.Contains (o))
846 throw new InvalidOperationException ("A circular reference was detected while serializing an object of type " + o.GetType().Name);
848 serializedObjects [o] = o;
851 string prefix = null;
853 if (topLevelElement && ns != null && ns.Length != 0)
855 if (namespaces != null)
856 foreach (XmlQualifiedName qn in namespaces)
857 if (qn.Namespace == ns) {
859 writePrefixed = true;
864 if (writePrefixed && ns != string.Empty)
866 name = XmlCustomFormatter.FromXmlName (name);
869 prefix = Writer.LookupPrefix (ns);
870 if (prefix == null || prefix.Length == 0)
871 prefix = "q" + (++qnameCount);
872 Writer.WriteStartElement (prefix, name, ns);
874 Writer.WriteStartElement (name, ns);
878 if (namespaces != null) {
879 foreach (XmlQualifiedName qn in namespaces)
881 string currentPrefix = Writer.LookupPrefix (qn.Namespace);
882 if (currentPrefix != null && currentPrefix.Length != 0) continue;
884 WriteAttribute ("xmlns",qn.Name,xmlNamespace,qn.Namespace);
887 topLevelElement = false;
891 protected void WriteTypedPrimitive (string name, string ns, object o, bool xsiType)
894 TypeData td = TypeTranslator.GetTypeData (o.GetType (), null, true);
895 if (td.SchemaType != SchemaTypes.Primitive)
896 throw new InvalidOperationException (String.Format ("The type of the argument object '{0}' is not primitive.", td.FullTypeName));
899 ns = td.IsXsdType ? XmlSchema.Namespace : XmlSerializer.WsdlTypesNamespace;
903 name = XmlCustomFormatter.FromXmlName (name);
904 Writer.WriteStartElement (name, ns);
906 if (o is XmlQualifiedName)
907 value = FromXmlQualifiedName ((XmlQualifiedName) o);
909 value = XmlCustomFormatter.ToXmlString (td, o);
913 if (td.SchemaType != SchemaTypes.Primitive)
914 throw new InvalidOperationException (string.Format (unexpectedTypeError, o.GetType().FullName));
915 WriteXsiType (td.XmlType, td.IsXsdType ? XmlSchema.Namespace : XmlSerializer.WsdlTypesNamespace);
920 Writer.WriteEndElement ();
923 protected void WriteValue (byte[] value)
925 Writer.WriteBase64 (value, 0, value.Length);
928 protected void WriteValue (string value)
931 Writer.WriteString (value);
935 protected void WriteXmlAttribute (XmlNode node)
937 WriteXmlAttribute (node, null);
940 protected void WriteXmlAttribute (XmlNode node, object container)
942 XmlAttribute attr = node as XmlAttribute;
944 throw new InvalidOperationException ("The node must be either type XmlAttribute or a derived type.");
946 if (attr.NamespaceURI == XmlSerializer.WsdlNamespace)
948 // The wsdl arrayType attribute needs special handling
949 if (attr.LocalName == "arrayType") {
950 string ns, type, dimensions;
951 TypeTranslator.ParseArrayType (attr.Value, out type, out ns, out dimensions);
952 string value = GetQualifiedName (type + dimensions, ns);
953 WriteAttribute (attr.Prefix, attr.LocalName, attr.NamespaceURI, value);
958 WriteAttribute (attr.Prefix, attr.LocalName, attr.NamespaceURI, attr.Value);
962 protected void WriteXsiType (string name, string ns)
964 if (ns != null && ns != string.Empty)
965 WriteAttribute ("type", XmlSchema.InstanceNamespace, GetQualifiedName (name, ns));
967 WriteAttribute ("type", XmlSchema.InstanceNamespace, name);
972 protected Exception CreateInvalidAnyTypeException (object o)
975 return new InvalidOperationException ("null is invalid as anyType in XmlSerializer");
977 return CreateInvalidAnyTypeException (o.GetType ());
980 protected Exception CreateInvalidAnyTypeException (Type type)
982 return new InvalidOperationException (String.Format ("An object of type '{0}' is invalid as anyType in XmlSerializer", type));
985 protected Exception CreateInvalidEnumValueException (object value, string typeName)
987 return new InvalidOperationException (string.Format(CultureInfo.CurrentCulture,
988 "'{0}' is not a valid value for {1}.", value, typeName));
991 protected static string FromEnum (long value, string[] values, long[] ids, string typeName)
993 return XmlCustomFormatter.FromEnum (value, values, ids, typeName);
997 protected string FromXmlQualifiedName (XmlQualifiedName xmlQualifiedName, bool ignoreEmpty)
999 throw new NotImplementedException ();
1003 protected static Assembly ResolveDynamicAssembly (string assemblyFullName)
1005 throw new NotImplementedException ();
1009 protected bool EscapeName
1011 get { throw new NotImplementedException(); }
1012 set { throw new NotImplementedException(); }
1018 class WriteCallbackInfo
1021 public string TypeName;
1022 public string TypeNs;
1023 public XmlSerializationWriteCallback Callback;