mscorlib(4.0.0.0) API with additions
XmlSerializationWriter.cs
1 using System.Collections;
3 using System.Reflection;
4 using System.Text;
5 using System.Xml.Schema;
6 
8 {
11  {
12  internal class TypeEntry
13  {
14  internal XmlSerializationWriteCallback callback;
15 
16  internal string typeNs;
17 
18  internal string typeName;
19 
20  internal Type type;
21  }
22 
23  private XmlWriter w;
24 
25  private XmlSerializerNamespaces namespaces;
26 
27  private int tempNamespacePrefix;
28 
29  private Hashtable usedPrefixes;
30 
31  private Hashtable references;
32 
33  private string idBase;
34 
35  private int nextId;
36 
37  private Hashtable typeEntries;
38 
39  private ArrayList referencesToWrite;
40 
41  private Hashtable objectsInUse;
42 
43  private string aliasBase = "q";
44 
45  private bool soap12;
46 
47  private bool escapeName = true;
48 
52  protected bool EscapeName
53  {
54  get
55  {
56  return escapeName;
57  }
58  set
59  {
60  escapeName = value;
61  }
62  }
63 
66  protected XmlWriter Writer
67  {
68  get
69  {
70  return w;
71  }
72  set
73  {
74  w = value;
75  }
76  }
77 
80  protected ArrayList Namespaces
81  {
82  get
83  {
84  if (namespaces != null)
85  {
86  return namespaces.NamespaceList;
87  }
88  return null;
89  }
90  set
91  {
92  if (value == null)
93  {
94  namespaces = null;
95  return;
96  }
97  XmlQualifiedName[] array = (XmlQualifiedName[])value.ToArray(typeof(XmlQualifiedName));
98  namespaces = new XmlSerializerNamespaces(array);
99  }
100  }
101 
102  internal void Init(XmlWriter w, XmlSerializerNamespaces namespaces, string encodingStyle, string idBase, TempAssembly tempAssembly)
103  {
104  this.w = w;
105  this.namespaces = namespaces;
106  soap12 = (encodingStyle == "http://www.w3.org/2003/05/soap-encoding");
107  this.idBase = idBase;
108  Init(tempAssembly);
109  }
110 
114  protected static byte[] FromByteArrayBase64(byte[] value)
115  {
116  return value;
117  }
118 
122  protected static Assembly ResolveDynamicAssembly(string assemblyFullName)
123  {
124  return DynamicAssemblies.Get(assemblyFullName);
125  }
126 
130  protected static string FromByteArrayHex(byte[] value)
131  {
132  return XmlCustomFormatter.FromByteArrayHex(value);
133  }
134 
138  protected static string FromDateTime(DateTime value)
139  {
140  return XmlCustomFormatter.FromDateTime(value);
141  }
142 
146  protected static string FromDate(DateTime value)
147  {
148  return XmlCustomFormatter.FromDate(value);
149  }
150 
154  protected static string FromTime(DateTime value)
155  {
156  return XmlCustomFormatter.FromTime(value);
157  }
158 
162  protected static string FromChar(char value)
163  {
164  return XmlCustomFormatter.FromChar(value);
165  }
166 
172  protected static string FromEnum(long value, string[] values, long[] ids)
173  {
174  return XmlCustomFormatter.FromEnum(value, values, ids, null);
175  }
176 
183  protected static string FromEnum(long value, string[] values, long[] ids, string typeName)
184  {
185  return XmlCustomFormatter.FromEnum(value, values, ids, typeName);
186  }
187 
191  protected static string FromXmlName(string name)
192  {
193  return XmlCustomFormatter.FromXmlName(name);
194  }
195 
199  protected static string FromXmlNCName(string ncName)
200  {
201  return XmlCustomFormatter.FromXmlNCName(ncName);
202  }
203 
207  protected static string FromXmlNmToken(string nmToken)
208  {
209  return XmlCustomFormatter.FromXmlNmToken(nmToken);
210  }
211 
215  protected static string FromXmlNmTokens(string nmTokens)
216  {
217  return XmlCustomFormatter.FromXmlNmTokens(nmTokens);
218  }
219 
223  protected void WriteXsiType(string name, string ns)
224  {
225  WriteAttribute("type", "http://www.w3.org/2001/XMLSchema-instance", GetQualifiedName(name, ns));
226  }
227 
228  private XmlQualifiedName GetPrimitiveTypeName(Type type)
229  {
230  return GetPrimitiveTypeName(type, throwIfUnknown: true);
231  }
232 
233  private XmlQualifiedName GetPrimitiveTypeName(Type type, bool throwIfUnknown)
234  {
235  XmlQualifiedName primitiveTypeNameInternal = GetPrimitiveTypeNameInternal(type);
236  if (throwIfUnknown && primitiveTypeNameInternal == null)
237  {
238  throw CreateUnknownTypeException(type);
239  }
240  return primitiveTypeNameInternal;
241  }
242 
243  internal static XmlQualifiedName GetPrimitiveTypeNameInternal(Type type)
244  {
245  string ns = "http://www.w3.org/2001/XMLSchema";
246  string name;
247  switch (Type.GetTypeCode(type))
248  {
249  case TypeCode.String:
250  name = "string";
251  break;
252  case TypeCode.Int32:
253  name = "int";
254  break;
255  case TypeCode.Boolean:
256  name = "boolean";
257  break;
258  case TypeCode.Int16:
259  name = "short";
260  break;
261  case TypeCode.Int64:
262  name = "long";
263  break;
264  case TypeCode.Single:
265  name = "float";
266  break;
267  case TypeCode.Double:
268  name = "double";
269  break;
270  case TypeCode.Decimal:
271  name = "decimal";
272  break;
273  case TypeCode.DateTime:
274  name = "dateTime";
275  break;
276  case TypeCode.Byte:
277  name = "unsignedByte";
278  break;
279  case TypeCode.SByte:
280  name = "byte";
281  break;
282  case TypeCode.UInt16:
283  name = "unsignedShort";
284  break;
285  case TypeCode.UInt32:
286  name = "unsignedInt";
287  break;
288  case TypeCode.UInt64:
289  name = "unsignedLong";
290  break;
291  case TypeCode.Char:
292  name = "char";
293  ns = "http://microsoft.com/wsdl/types/";
294  break;
295  default:
296  if (type == typeof(XmlQualifiedName))
297  {
298  name = "QName";
299  break;
300  }
301  if (type == typeof(byte[]))
302  {
303  name = "base64Binary";
304  break;
305  }
306  if (type == typeof(TimeSpan) && System.LocalAppContextSwitches.EnableTimeSpanSerialization)
307  {
308  name = "TimeSpan";
309  break;
310  }
311  if (type == typeof(Guid))
312  {
313  name = "guid";
314  ns = "http://microsoft.com/wsdl/types/";
315  break;
316  }
317  if (type == typeof(XmlNode[]))
318  {
319  name = "anyType";
320  break;
321  }
322  return null;
323  }
324  return new XmlQualifiedName(name, ns);
325  }
326 
333  protected void WriteTypedPrimitive(string name, string ns, object o, bool xsiType)
334  {
335  string text = null;
336  string ns2 = "http://www.w3.org/2001/XMLSchema";
337  bool flag = true;
338  bool flag2 = false;
339  Type type = o.GetType();
340  bool flag3 = false;
341  string text2;
342  switch (Type.GetTypeCode(type))
343  {
344  case TypeCode.String:
345  text = (string)o;
346  text2 = "string";
347  flag = false;
348  break;
349  case TypeCode.Int32:
350  text = XmlConvert.ToString((int)o);
351  text2 = "int";
352  break;
353  case TypeCode.Boolean:
354  text = XmlConvert.ToString((bool)o);
355  text2 = "boolean";
356  break;
357  case TypeCode.Int16:
358  text = XmlConvert.ToString((short)o);
359  text2 = "short";
360  break;
361  case TypeCode.Int64:
362  text = XmlConvert.ToString((long)o);
363  text2 = "long";
364  break;
365  case TypeCode.Single:
366  text = XmlConvert.ToString((float)o);
367  text2 = "float";
368  break;
369  case TypeCode.Double:
370  text = XmlConvert.ToString((double)o);
371  text2 = "double";
372  break;
373  case TypeCode.Decimal:
374  text = XmlConvert.ToString((decimal)o);
375  text2 = "decimal";
376  break;
377  case TypeCode.DateTime:
378  text = FromDateTime((DateTime)o);
379  text2 = "dateTime";
380  break;
381  case TypeCode.Char:
382  text = FromChar((char)o);
383  text2 = "char";
384  ns2 = "http://microsoft.com/wsdl/types/";
385  break;
386  case TypeCode.Byte:
387  text = XmlConvert.ToString((byte)o);
388  text2 = "unsignedByte";
389  break;
390  case TypeCode.SByte:
391  text = XmlConvert.ToString((sbyte)o);
392  text2 = "byte";
393  break;
394  case TypeCode.UInt16:
395  text = XmlConvert.ToString((ushort)o);
396  text2 = "unsignedShort";
397  break;
398  case TypeCode.UInt32:
399  text = XmlConvert.ToString((uint)o);
400  text2 = "unsignedInt";
401  break;
402  case TypeCode.UInt64:
403  text = XmlConvert.ToString((ulong)o);
404  text2 = "unsignedLong";
405  break;
406  default:
407  if (type == typeof(XmlQualifiedName))
408  {
409  text2 = "QName";
410  flag3 = true;
411  if (name == null)
412  {
413  w.WriteStartElement(text2, ns2);
414  }
415  else
416  {
417  w.WriteStartElement(name, ns);
418  }
419  text = FromXmlQualifiedName((XmlQualifiedName)o, ignoreEmpty: false);
420  break;
421  }
422  if (type == typeof(byte[]))
423  {
424  text = string.Empty;
425  flag2 = true;
426  text2 = "base64Binary";
427  break;
428  }
429  if (type == typeof(Guid))
430  {
431  text = XmlConvert.ToString((Guid)o);
432  text2 = "guid";
433  ns2 = "http://microsoft.com/wsdl/types/";
434  break;
435  }
436  if (type == typeof(TimeSpan) && System.LocalAppContextSwitches.EnableTimeSpanSerialization)
437  {
438  text = XmlConvert.ToString((TimeSpan)o);
439  text2 = "TimeSpan";
440  break;
441  }
442  if (typeof(XmlNode[]).IsAssignableFrom(type))
443  {
444  if (name == null)
445  {
446  w.WriteStartElement("anyType", "http://www.w3.org/2001/XMLSchema");
447  }
448  else
449  {
450  w.WriteStartElement(name, ns);
451  }
452  XmlNode[] array = (XmlNode[])o;
453  for (int i = 0; i < array.Length; i++)
454  {
455  if (array[i] != null)
456  {
457  array[i].WriteTo(w);
458  }
459  }
460  w.WriteEndElement();
461  return;
462  }
463  throw CreateUnknownTypeException(type);
464  }
465  if (!flag3)
466  {
467  if (name == null)
468  {
469  w.WriteStartElement(text2, ns2);
470  }
471  else
472  {
473  w.WriteStartElement(name, ns);
474  }
475  }
476  if (xsiType)
477  {
478  WriteXsiType(text2, ns2);
479  }
480  if (text == null)
481  {
482  w.WriteAttributeString("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
483  }
484  else if (flag2)
485  {
486  XmlCustomFormatter.WriteArrayBase64(w, (byte[])o, 0, ((byte[])o).Length);
487  }
488  else if (flag)
489  {
490  w.WriteRaw(text);
491  }
492  else
493  {
494  w.WriteString(text);
495  }
496  w.WriteEndElement();
497  }
498 
499  private string GetQualifiedName(string name, string ns)
500  {
501  if (ns == null || ns.Length == 0)
502  {
503  return name;
504  }
505  string text = w.LookupPrefix(ns);
506  if (text == null)
507  {
508  if (ns == "http://www.w3.org/XML/1998/namespace")
509  {
510  text = "xml";
511  }
512  else
513  {
514  text = NextPrefix();
515  WriteAttribute("xmlns", text, null, ns);
516  }
517  }
518  else if (text.Length == 0)
519  {
520  return name;
521  }
522  return text + ":" + name;
523  }
524 
528  protected string FromXmlQualifiedName(XmlQualifiedName xmlQualifiedName)
529  {
530  return FromXmlQualifiedName(xmlQualifiedName, ignoreEmpty: true);
531  }
532 
538  protected string FromXmlQualifiedName(XmlQualifiedName xmlQualifiedName, bool ignoreEmpty)
539  {
540  if (xmlQualifiedName == null)
541  {
542  return null;
543  }
544  if (xmlQualifiedName.IsEmpty && ignoreEmpty)
545  {
546  return null;
547  }
548  return GetQualifiedName(EscapeName ? XmlConvert.EncodeLocalName(xmlQualifiedName.Name) : xmlQualifiedName.Name, xmlQualifiedName.Namespace);
549  }
550 
553  protected void WriteStartElement(string name)
554  {
555  WriteStartElement(name, null, null, writePrefixed: false, null);
556  }
557 
561  protected void WriteStartElement(string name, string ns)
562  {
563  WriteStartElement(name, ns, null, writePrefixed: false, null);
564  }
565 
571  protected void WriteStartElement(string name, string ns, bool writePrefixed)
572  {
573  WriteStartElement(name, ns, null, writePrefixed, null);
574  }
575 
580  protected void WriteStartElement(string name, string ns, object o)
581  {
582  WriteStartElement(name, ns, o, writePrefixed: false, null);
583  }
584 
591  protected void WriteStartElement(string name, string ns, object o, bool writePrefixed)
592  {
593  WriteStartElement(name, ns, o, writePrefixed, null);
594  }
595 
603  protected void WriteStartElement(string name, string ns, object o, bool writePrefixed, XmlSerializerNamespaces xmlns)
604  {
605  if (o != null && objectsInUse != null)
606  {
607  if (objectsInUse.ContainsKey(o))
608  {
609  throw new InvalidOperationException(Res.GetString("XmlCircularReference", o.GetType().FullName));
610  }
611  objectsInUse.Add(o, o);
612  }
613  string text = null;
614  bool flag = false;
615  if (namespaces != null)
616  {
617  foreach (string key in namespaces.Namespaces.Keys)
618  {
619  string text3 = (string)namespaces.Namespaces[key];
620  if (key.Length > 0 && text3 == ns)
621  {
622  text = key;
623  }
624  if (key.Length == 0)
625  {
626  if (text3 == null || text3.Length == 0)
627  {
628  flag = true;
629  }
630  if (ns != text3)
631  {
632  writePrefixed = true;
633  }
634  }
635  }
636  usedPrefixes = ListUsedPrefixes(namespaces.Namespaces, aliasBase);
637  }
638  if (writePrefixed && text == null && ns != null && ns.Length > 0)
639  {
640  text = w.LookupPrefix(ns);
641  if (text == null || text.Length == 0)
642  {
643  text = NextPrefix();
644  }
645  }
646  if (text == null && xmlns != null)
647  {
648  text = xmlns.LookupPrefix(ns);
649  }
650  if (flag && text == null && ns != null && ns.Length != 0)
651  {
652  text = NextPrefix();
653  }
654  w.WriteStartElement(text, name, ns);
655  if (namespaces != null)
656  {
657  foreach (string key2 in namespaces.Namespaces.Keys)
658  {
659  string text5 = (string)namespaces.Namespaces[key2];
660  if (key2.Length != 0 || (text5 != null && text5.Length != 0))
661  {
662  if (text5 == null || text5.Length == 0)
663  {
664  if (key2.Length > 0)
665  {
666  throw new InvalidOperationException(Res.GetString("XmlInvalidXmlns", key2));
667  }
668  WriteAttribute("xmlns", key2, null, text5);
669  }
670  else if (w.LookupPrefix(text5) == null)
671  {
672  if (text == null && key2.Length == 0)
673  {
674  break;
675  }
676  WriteAttribute("xmlns", key2, null, text5);
677  }
678  }
679  }
680  }
682  }
683 
684  private Hashtable ListUsedPrefixes(Hashtable nsList, string prefix)
685  {
686  Hashtable hashtable = new Hashtable();
687  int length = prefix.Length;
688  foreach (string key in namespaces.Namespaces.Keys)
689  {
690  if (key.Length > length)
691  {
692  string text2 = key;
693  int length2 = text2.Length;
694  if (text2.Length > length && text2.Length <= length + "2147483647".Length && text2.StartsWith(prefix, StringComparison.Ordinal))
695  {
696  bool flag = true;
697  for (int i = length; i < text2.Length; i++)
698  {
699  if (!char.IsDigit(text2, i))
700  {
701  flag = false;
702  break;
703  }
704  }
705  if (flag)
706  {
707  long num = long.Parse(text2.Substring(length), CultureInfo.InvariantCulture);
708  if (num <= int.MaxValue)
709  {
710  int num2 = (int)num;
711  if (!hashtable.ContainsKey(num2))
712  {
713  hashtable.Add(num2, num2);
714  }
715  }
716  }
717  }
718  }
719  }
720  if (hashtable.Count > 0)
721  {
722  return hashtable;
723  }
724  return null;
725  }
726 
729  protected void WriteNullTagEncoded(string name)
730  {
731  WriteNullTagEncoded(name, null);
732  }
733 
737  protected void WriteNullTagEncoded(string name, string ns)
738  {
739  if (name != null && name.Length != 0)
740  {
741  WriteStartElement(name, ns, null, writePrefixed: true);
742  w.WriteAttributeString("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
743  w.WriteEndElement();
744  }
745  }
746 
749  protected void WriteNullTagLiteral(string name)
750  {
751  WriteNullTagLiteral(name, null);
752  }
753 
757  protected void WriteNullTagLiteral(string name, string ns)
758  {
759  if (name != null && name.Length != 0)
760  {
761  WriteStartElement(name, ns, null, writePrefixed: false);
762  w.WriteAttributeString("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
763  w.WriteEndElement();
764  }
765  }
766 
769  protected void WriteEmptyTag(string name)
770  {
771  WriteEmptyTag(name, null);
772  }
773 
777  protected void WriteEmptyTag(string name, string ns)
778  {
779  if (name != null && name.Length != 0)
780  {
781  WriteStartElement(name, ns, null, writePrefixed: false);
782  w.WriteEndElement();
783  }
784  }
785 
787  protected void WriteEndElement()
788  {
789  w.WriteEndElement();
790  }
791 
794  protected void WriteEndElement(object o)
795  {
796  w.WriteEndElement();
797  if (o != null && objectsInUse != null)
798  {
799  objectsInUse.Remove(o);
800  }
801  }
802 
809  protected void WriteSerializable(IXmlSerializable serializable, string name, string ns, bool isNullable)
810  {
811  WriteSerializable(serializable, name, ns, isNullable, wrapped: true);
812  }
813 
822  protected void WriteSerializable(IXmlSerializable serializable, string name, string ns, bool isNullable, bool wrapped)
823  {
824  if (serializable == null)
825  {
826  if (isNullable)
827  {
828  WriteNullTagLiteral(name, ns);
829  }
830  return;
831  }
832  if (wrapped)
833  {
834  w.WriteStartElement(name, ns);
835  }
836  serializable.WriteXml(w);
837  if (wrapped)
838  {
839  w.WriteEndElement();
840  }
841  }
842 
848  protected void WriteNullableStringEncoded(string name, string ns, string value, XmlQualifiedName xsiType)
849  {
850  if (value == null)
851  {
852  WriteNullTagEncoded(name, ns);
853  }
854  else
855  {
856  WriteElementString(name, ns, value, xsiType);
857  }
858  }
859 
864  protected void WriteNullableStringLiteral(string name, string ns, string value)
865  {
866  if (value == null)
867  {
868  WriteNullTagLiteral(name, ns);
869  }
870  else
871  {
872  WriteElementString(name, ns, value, null);
873  }
874  }
875 
881  protected void WriteNullableStringEncodedRaw(string name, string ns, string value, XmlQualifiedName xsiType)
882  {
883  if (value == null)
884  {
885  WriteNullTagEncoded(name, ns);
886  }
887  else
888  {
889  WriteElementStringRaw(name, ns, value, xsiType);
890  }
891  }
892 
898  protected void WriteNullableStringEncodedRaw(string name, string ns, byte[] value, XmlQualifiedName xsiType)
899  {
900  if (value == null)
901  {
902  WriteNullTagEncoded(name, ns);
903  }
904  else
905  {
906  WriteElementStringRaw(name, ns, value, xsiType);
907  }
908  }
909 
914  protected void WriteNullableStringLiteralRaw(string name, string ns, string value)
915  {
916  if (value == null)
917  {
918  WriteNullTagLiteral(name, ns);
919  }
920  else
921  {
922  WriteElementStringRaw(name, ns, value, null);
923  }
924  }
925 
930  protected void WriteNullableStringLiteralRaw(string name, string ns, byte[] value)
931  {
932  if (value == null)
933  {
934  WriteNullTagLiteral(name, ns);
935  }
936  else
937  {
938  WriteElementStringRaw(name, ns, value, null);
939  }
940  }
941 
947  protected void WriteNullableQualifiedNameEncoded(string name, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
948  {
949  if (value == null)
950  {
951  WriteNullTagEncoded(name, ns);
952  }
953  else
954  {
955  WriteElementQualifiedName(name, ns, value, xsiType);
956  }
957  }
958 
963  protected void WriteNullableQualifiedNameLiteral(string name, string ns, XmlQualifiedName value)
964  {
965  if (value == null)
966  {
967  WriteNullTagLiteral(name, ns);
968  }
969  else
970  {
971  WriteElementQualifiedName(name, ns, value, null);
972  }
973  }
974 
983  protected void WriteElementEncoded(XmlNode node, string name, string ns, bool isNullable, bool any)
984  {
985  if (node == null)
986  {
987  if (isNullable)
988  {
989  WriteNullTagEncoded(name, ns);
990  }
991  }
992  else
993  {
994  WriteElement(node, name, ns, isNullable, any);
995  }
996  }
997 
1006  protected void WriteElementLiteral(XmlNode node, string name, string ns, bool isNullable, bool any)
1007  {
1008  if (node == null)
1009  {
1010  if (isNullable)
1011  {
1012  WriteNullTagLiteral(name, ns);
1013  }
1014  }
1015  else
1016  {
1017  WriteElement(node, name, ns, isNullable, any);
1018  }
1019  }
1020 
1021  private void WriteElement(XmlNode node, string name, string ns, bool isNullable, bool any)
1022  {
1023  if (typeof(XmlAttribute).IsAssignableFrom(node.GetType()))
1024  {
1025  throw new InvalidOperationException(Res.GetString("XmlNoAttributeHere"));
1026  }
1027  if (node is XmlDocument)
1028  {
1029  node = ((XmlDocument)node).DocumentElement;
1030  if (node == null)
1031  {
1032  if (isNullable)
1033  {
1034  WriteNullTagEncoded(name, ns);
1035  }
1036  return;
1037  }
1038  }
1039  if (any)
1040  {
1041  if (node is XmlElement && name != null && name.Length > 0 && (node.LocalName != name || node.NamespaceURI != ns))
1042  {
1043  throw new InvalidOperationException(Res.GetString("XmlElementNameMismatch", node.LocalName, node.NamespaceURI, name, ns));
1044  }
1045  }
1046  else
1047  {
1048  w.WriteStartElement(name, ns);
1049  }
1050  node.WriteTo(w);
1051  if (!any)
1052  {
1053  w.WriteEndElement();
1054  }
1055  }
1056 
1061  {
1062  return CreateUnknownTypeException(o.GetType());
1063  }
1064 
1069  {
1070  if (typeof(IXmlSerializable).IsAssignableFrom(type))
1071  {
1072  return new InvalidOperationException(Res.GetString("XmlInvalidSerializable", type.FullName));
1073  }
1074  TypeDesc typeDesc = new TypeScope().GetTypeDesc(type);
1075  if (!typeDesc.IsStructLike)
1076  {
1077  return new InvalidOperationException(Res.GetString("XmlInvalidUseOfType", type.FullName));
1078  }
1079  return new InvalidOperationException(Res.GetString("XmlUnxpectedType", type.FullName));
1080  }
1081 
1087  protected Exception CreateMismatchChoiceException(string value, string elementName, string enumValue)
1088  {
1089  return new InvalidOperationException(Res.GetString("XmlChoiceMismatchChoiceException", elementName, value, enumValue));
1090  }
1091 
1096  protected Exception CreateUnknownAnyElementException(string name, string ns)
1097  {
1098  return new InvalidOperationException(Res.GetString("XmlUnknownAnyElement", name, ns));
1099  }
1100 
1105  protected Exception CreateInvalidChoiceIdentifierValueException(string type, string identifier)
1106  {
1107  return new InvalidOperationException(Res.GetString("XmlInvalidChoiceIdentifierValue", type, identifier));
1108  }
1109 
1116  protected Exception CreateChoiceIdentifierValueException(string value, string identifier, string name, string ns)
1117  {
1118  return new InvalidOperationException(Res.GetString("XmlChoiceIdentifierMismatch", value, identifier, name, ns));
1119  }
1120 
1125  protected Exception CreateInvalidEnumValueException(object value, string typeName)
1126  {
1127  return new InvalidOperationException(Res.GetString("XmlUnknownConstant", value, typeName));
1128  }
1129 
1134  {
1135  return CreateInvalidAnyTypeException(o.GetType());
1136  }
1137 
1142  {
1143  return new InvalidOperationException(Res.GetString("XmlIllegalAnyElement", type.FullName));
1144  }
1145 
1150  protected void WriteReferencingElement(string n, string ns, object o)
1151  {
1152  WriteReferencingElement(n, ns, o, isNullable: false);
1153  }
1154 
1161  protected void WriteReferencingElement(string n, string ns, object o, bool isNullable)
1162  {
1163  if (o == null)
1164  {
1165  if (isNullable)
1166  {
1167  WriteNullTagEncoded(n, ns);
1168  }
1169  return;
1170  }
1171  WriteStartElement(n, ns, null, writePrefixed: true);
1172  if (soap12)
1173  {
1174  w.WriteAttributeString("ref", "http://www.w3.org/2003/05/soap-encoding", GetId(o, addToReferencesList: true));
1175  }
1176  else
1177  {
1178  w.WriteAttributeString("href", "#" + GetId(o, addToReferencesList: true));
1179  }
1180  w.WriteEndElement();
1181  }
1182 
1183  private bool IsIdDefined(object o)
1184  {
1185  if (references != null)
1186  {
1187  return references.Contains(o);
1188  }
1189  return false;
1190  }
1191 
1192  private string GetId(object o, bool addToReferencesList)
1193  {
1194  if (references == null)
1195  {
1196  references = new Hashtable();
1197  referencesToWrite = new ArrayList();
1198  }
1199  string text = (string)references[o];
1200  if (text == null)
1201  {
1202  text = idBase + "id" + (++nextId).ToString(CultureInfo.InvariantCulture);
1203  references.Add(o, text);
1204  if (addToReferencesList)
1205  {
1206  referencesToWrite.Add(o);
1207  }
1208  }
1209  return text;
1210  }
1211 
1214  protected void WriteId(object o)
1215  {
1216  WriteId(o, addToReferencesList: true);
1217  }
1218 
1219  private void WriteId(object o, bool addToReferencesList)
1220  {
1221  if (soap12)
1222  {
1223  w.WriteAttributeString("id", "http://www.w3.org/2003/05/soap-encoding", GetId(o, addToReferencesList));
1224  }
1225  else
1226  {
1227  w.WriteAttributeString("id", GetId(o, addToReferencesList));
1228  }
1229  }
1230 
1233  protected void WriteXmlAttribute(XmlNode node)
1234  {
1235  WriteXmlAttribute(node, null);
1236  }
1237 
1241  protected void WriteXmlAttribute(XmlNode node, object container)
1242  {
1243  XmlAttribute xmlAttribute = node as XmlAttribute;
1244  if (xmlAttribute == null)
1245  {
1246  throw new InvalidOperationException(Res.GetString("XmlNeedAttributeHere"));
1247  }
1248  if (xmlAttribute.Value != null)
1249  {
1250  if (xmlAttribute.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && xmlAttribute.LocalName == "arrayType")
1251  {
1252  string dims = default(string);
1253  XmlQualifiedName xmlQualifiedName = TypeScope.ParseWsdlArrayType(xmlAttribute.Value, out dims, (container is XmlSchemaObject) ? ((XmlSchemaObject)container) : null);
1254  string value = FromXmlQualifiedName(xmlQualifiedName, ignoreEmpty: true) + dims;
1255  WriteAttribute("arrayType", "http://schemas.xmlsoap.org/wsdl/", value);
1256  }
1257  else
1258  {
1259  WriteAttribute(xmlAttribute.Name, xmlAttribute.NamespaceURI, xmlAttribute.Value);
1260  }
1261  }
1262  }
1263 
1268  protected void WriteAttribute(string localName, string ns, string value)
1269  {
1270  if (value == null || localName == "xmlns" || localName.StartsWith("xmlns:", StringComparison.Ordinal))
1271  {
1272  return;
1273  }
1274  int num = localName.IndexOf(':');
1275  if (num < 0)
1276  {
1277  if (ns == "http://www.w3.org/XML/1998/namespace")
1278  {
1279  string text = w.LookupPrefix(ns);
1280  if (text == null || text.Length == 0)
1281  {
1282  text = "xml";
1283  }
1284  w.WriteAttributeString(text, localName, ns, value);
1285  }
1286  else
1287  {
1288  w.WriteAttributeString(localName, ns, value);
1289  }
1290  }
1291  else
1292  {
1293  string prefix = localName.Substring(0, num);
1294  w.WriteAttributeString(prefix, localName.Substring(num + 1), ns, value);
1295  }
1296  }
1297 
1302  protected void WriteAttribute(string localName, string ns, byte[] value)
1303  {
1304  if (value == null || localName == "xmlns" || localName.StartsWith("xmlns:", StringComparison.Ordinal))
1305  {
1306  return;
1307  }
1308  int num = localName.IndexOf(':');
1309  if (num < 0)
1310  {
1311  if (ns == "http://www.w3.org/XML/1998/namespace")
1312  {
1313  string text = w.LookupPrefix(ns);
1314  if (text == null || text.Length == 0)
1315  {
1316  text = "xml";
1317  }
1318  w.WriteStartAttribute("xml", localName, ns);
1319  }
1320  else
1321  {
1322  w.WriteStartAttribute(null, localName, ns);
1323  }
1324  }
1325  else
1326  {
1327  string text2 = localName.Substring(0, num);
1328  text2 = w.LookupPrefix(ns);
1329  w.WriteStartAttribute(text2, localName.Substring(num + 1), ns);
1330  }
1331  XmlCustomFormatter.WriteArrayBase64(w, value, 0, value.Length);
1332  w.WriteEndAttribute();
1333  }
1334 
1338  protected void WriteAttribute(string localName, string value)
1339  {
1340  if (value != null)
1341  {
1342  w.WriteAttributeString(localName, null, value);
1343  }
1344  }
1345 
1349  protected void WriteAttribute(string localName, byte[] value)
1350  {
1351  if (value != null)
1352  {
1353  w.WriteStartAttribute(null, localName, null);
1354  XmlCustomFormatter.WriteArrayBase64(w, value, 0, value.Length);
1355  w.WriteEndAttribute();
1356  }
1357  }
1358 
1364  protected void WriteAttribute(string prefix, string localName, string ns, string value)
1365  {
1366  if (value != null)
1367  {
1368  w.WriteAttributeString(prefix, localName, null, value);
1369  }
1370  }
1371 
1374  protected void WriteValue(string value)
1375  {
1376  if (value != null)
1377  {
1378  w.WriteString(value);
1379  }
1380  }
1381 
1384  protected void WriteValue(byte[] value)
1385  {
1386  if (value != null)
1387  {
1388  XmlCustomFormatter.WriteArrayBase64(w, value, 0, value.Length);
1389  }
1390  }
1391 
1393  protected void WriteStartDocument()
1394  {
1395  if (w.WriteState == WriteState.Start)
1396  {
1397  w.WriteStartDocument();
1398  }
1399  }
1400 
1404  protected void WriteElementString(string localName, string value)
1405  {
1406  WriteElementString(localName, null, value, null);
1407  }
1408 
1413  protected void WriteElementString(string localName, string ns, string value)
1414  {
1415  WriteElementString(localName, ns, value, null);
1416  }
1417 
1422  protected void WriteElementString(string localName, string value, XmlQualifiedName xsiType)
1423  {
1424  WriteElementString(localName, null, value, xsiType);
1425  }
1426 
1432  protected void WriteElementString(string localName, string ns, string value, XmlQualifiedName xsiType)
1433  {
1434  if (value != null)
1435  {
1436  if (xsiType == null)
1437  {
1438  w.WriteElementString(localName, ns, value);
1439  return;
1440  }
1441  w.WriteStartElement(localName, ns);
1442  WriteXsiType(xsiType.Name, xsiType.Namespace);
1443  w.WriteString(value);
1444  w.WriteEndElement();
1445  }
1446  }
1447 
1451  protected void WriteElementStringRaw(string localName, string value)
1452  {
1453  WriteElementStringRaw(localName, null, value, null);
1454  }
1455 
1459  protected void WriteElementStringRaw(string localName, byte[] value)
1460  {
1461  WriteElementStringRaw(localName, null, value, null);
1462  }
1463 
1468  protected void WriteElementStringRaw(string localName, string ns, string value)
1469  {
1470  WriteElementStringRaw(localName, ns, value, null);
1471  }
1472 
1477  protected void WriteElementStringRaw(string localName, string ns, byte[] value)
1478  {
1479  WriteElementStringRaw(localName, ns, value, null);
1480  }
1481 
1486  protected void WriteElementStringRaw(string localName, string value, XmlQualifiedName xsiType)
1487  {
1488  WriteElementStringRaw(localName, null, value, xsiType);
1489  }
1490 
1495  protected void WriteElementStringRaw(string localName, byte[] value, XmlQualifiedName xsiType)
1496  {
1497  WriteElementStringRaw(localName, null, value, xsiType);
1498  }
1499 
1505  protected void WriteElementStringRaw(string localName, string ns, string value, XmlQualifiedName xsiType)
1506  {
1507  if (value != null)
1508  {
1509  w.WriteStartElement(localName, ns);
1510  if (xsiType != null)
1511  {
1512  WriteXsiType(xsiType.Name, xsiType.Namespace);
1513  }
1514  w.WriteRaw(value);
1515  w.WriteEndElement();
1516  }
1517  }
1518 
1524  protected void WriteElementStringRaw(string localName, string ns, byte[] value, XmlQualifiedName xsiType)
1525  {
1526  if (value != null)
1527  {
1528  w.WriteStartElement(localName, ns);
1529  if (xsiType != null)
1530  {
1531  WriteXsiType(xsiType.Name, xsiType.Namespace);
1532  }
1533  XmlCustomFormatter.WriteArrayBase64(w, value, 0, value.Length);
1534  w.WriteEndElement();
1535  }
1536  }
1537 
1541  protected void WriteRpcResult(string name, string ns)
1542  {
1543  if (soap12)
1544  {
1545  WriteElementQualifiedName("result", "http://www.w3.org/2003/05/soap-rpc", new XmlQualifiedName(name, ns), null);
1546  }
1547  }
1548 
1552  protected void WriteElementQualifiedName(string localName, XmlQualifiedName value)
1553  {
1554  WriteElementQualifiedName(localName, null, value, null);
1555  }
1556 
1561  protected void WriteElementQualifiedName(string localName, XmlQualifiedName value, XmlQualifiedName xsiType)
1562  {
1563  WriteElementQualifiedName(localName, null, value, xsiType);
1564  }
1565 
1570  protected void WriteElementQualifiedName(string localName, string ns, XmlQualifiedName value)
1571  {
1572  WriteElementQualifiedName(localName, ns, value, null);
1573  }
1574 
1580  protected void WriteElementQualifiedName(string localName, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
1581  {
1582  if (!(value == null))
1583  {
1584  if (value.Namespace == null || value.Namespace.Length == 0)
1585  {
1586  WriteStartElement(localName, ns, null, writePrefixed: true);
1587  WriteAttribute("xmlns", "");
1588  }
1589  else
1590  {
1591  w.WriteStartElement(localName, ns);
1592  }
1593  if (xsiType != null)
1594  {
1595  WriteXsiType(xsiType.Name, xsiType.Namespace);
1596  }
1597  w.WriteString(FromXmlQualifiedName(value, ignoreEmpty: false));
1598  w.WriteEndElement();
1599  }
1600  }
1601 
1607  protected void AddWriteCallback(Type type, string typeName, string typeNs, XmlSerializationWriteCallback callback)
1608  {
1609  TypeEntry typeEntry = new TypeEntry();
1610  typeEntry.typeName = typeName;
1611  typeEntry.typeNs = typeNs;
1612  typeEntry.type = type;
1613  typeEntry.callback = callback;
1614  typeEntries[type] = typeEntry;
1615  }
1616 
1617  private void WriteArray(string name, string ns, object o, Type type)
1618  {
1619  Type arrayElementType = TypeScope.GetArrayElementType(type, null);
1620  StringBuilder stringBuilder = new StringBuilder();
1621  if (!soap12)
1622  {
1623  while ((arrayElementType.IsArray || typeof(IEnumerable).IsAssignableFrom(arrayElementType)) && GetPrimitiveTypeName(arrayElementType, throwIfUnknown: false) == null)
1624  {
1625  arrayElementType = TypeScope.GetArrayElementType(arrayElementType, null);
1626  stringBuilder.Append("[]");
1627  }
1628  }
1629  string text;
1630  string ns2;
1631  if (arrayElementType == typeof(object))
1632  {
1633  text = "anyType";
1634  ns2 = "http://www.w3.org/2001/XMLSchema";
1635  }
1636  else
1637  {
1638  TypeEntry typeEntry = GetTypeEntry(arrayElementType);
1639  if (typeEntry != null)
1640  {
1641  text = typeEntry.typeName;
1642  ns2 = typeEntry.typeNs;
1643  }
1644  else if (soap12)
1645  {
1646  XmlQualifiedName primitiveTypeName = GetPrimitiveTypeName(arrayElementType, throwIfUnknown: false);
1647  if (primitiveTypeName != null)
1648  {
1649  text = primitiveTypeName.Name;
1650  ns2 = primitiveTypeName.Namespace;
1651  }
1652  else
1653  {
1654  Type baseType = arrayElementType.BaseType;
1655  while (baseType != null)
1656  {
1657  typeEntry = GetTypeEntry(baseType);
1658  if (typeEntry != null)
1659  {
1660  break;
1661  }
1662  baseType = baseType.BaseType;
1663  }
1664  if (typeEntry != null)
1665  {
1666  text = typeEntry.typeName;
1667  ns2 = typeEntry.typeNs;
1668  }
1669  else
1670  {
1671  text = "anyType";
1672  ns2 = "http://www.w3.org/2001/XMLSchema";
1673  }
1674  }
1675  }
1676  else
1677  {
1678  XmlQualifiedName primitiveTypeName2 = GetPrimitiveTypeName(arrayElementType);
1679  text = primitiveTypeName2.Name;
1680  ns2 = primitiveTypeName2.Namespace;
1681  }
1682  }
1683  if (stringBuilder.Length > 0)
1684  {
1685  text += stringBuilder.ToString();
1686  }
1687  if (soap12 && name != null && name.Length > 0)
1688  {
1689  WriteStartElement(name, ns, null, writePrefixed: false);
1690  }
1691  else
1692  {
1693  WriteStartElement("Array", "http://schemas.xmlsoap.org/soap/encoding/", null, writePrefixed: true);
1694  }
1695  WriteId(o, addToReferencesList: false);
1696  if (type.IsArray)
1697  {
1698  Array array = (Array)o;
1699  int length = array.Length;
1700  if (soap12)
1701  {
1702  w.WriteAttributeString("itemType", "http://www.w3.org/2003/05/soap-encoding", GetQualifiedName(text, ns2));
1703  w.WriteAttributeString("arraySize", "http://www.w3.org/2003/05/soap-encoding", length.ToString(CultureInfo.InvariantCulture));
1704  }
1705  else
1706  {
1707  w.WriteAttributeString("arrayType", "http://schemas.xmlsoap.org/soap/encoding/", GetQualifiedName(text, ns2) + "[" + length.ToString(CultureInfo.InvariantCulture) + "]");
1708  }
1709  for (int i = 0; i < length; i++)
1710  {
1711  WritePotentiallyReferencingElement("Item", "", array.GetValue(i), arrayElementType, suppressReference: false, isNullable: true);
1712  }
1713  }
1714  else
1715  {
1716  int num = typeof(ICollection).IsAssignableFrom(type) ? ((ICollection)o).Count : (-1);
1717  if (soap12)
1718  {
1719  w.WriteAttributeString("itemType", "http://www.w3.org/2003/05/soap-encoding", GetQualifiedName(text, ns2));
1720  if (num >= 0)
1721  {
1722  w.WriteAttributeString("arraySize", "http://www.w3.org/2003/05/soap-encoding", num.ToString(CultureInfo.InvariantCulture));
1723  }
1724  }
1725  else
1726  {
1727  string str = (num >= 0) ? ("[" + num + "]") : "[]";
1728  w.WriteAttributeString("arrayType", "http://schemas.xmlsoap.org/soap/encoding/", GetQualifiedName(text, ns2) + str);
1729  }
1730  IEnumerator enumerator = ((IEnumerable)o).GetEnumerator();
1731  if (enumerator != null)
1732  {
1733  while (enumerator.MoveNext())
1734  {
1735  WritePotentiallyReferencingElement("Item", "", enumerator.Current, arrayElementType, suppressReference: false, isNullable: true);
1736  }
1737  }
1738  }
1739  w.WriteEndElement();
1740  }
1741 
1746  protected void WritePotentiallyReferencingElement(string n, string ns, object o)
1747  {
1748  WritePotentiallyReferencingElement(n, ns, o, null, suppressReference: false, isNullable: false);
1749  }
1750 
1756  protected void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType)
1757  {
1758  WritePotentiallyReferencingElement(n, ns, o, ambientType, suppressReference: false, isNullable: false);
1759  }
1760 
1768  protected void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference)
1769  {
1770  WritePotentiallyReferencingElement(n, ns, o, ambientType, suppressReference, isNullable: false);
1771  }
1772 
1782  protected void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
1783  {
1784  if (o == null)
1785  {
1786  if (isNullable)
1787  {
1788  WriteNullTagEncoded(n, ns);
1789  }
1790  return;
1791  }
1792  Type type = o.GetType();
1793  if (Convert.GetTypeCode(o) == TypeCode.Object && !(o is Guid) && type != typeof(XmlQualifiedName) && !(o is XmlNode[]) && type != typeof(byte[]))
1794  {
1795  if ((suppressReference || soap12) && !IsIdDefined(o))
1796  {
1797  WriteReferencedElement(n, ns, o, ambientType);
1798  }
1799  else if (n == null)
1800  {
1801  TypeEntry typeEntry = GetTypeEntry(type);
1802  WriteReferencingElement(typeEntry.typeName, typeEntry.typeNs, o, isNullable);
1803  }
1804  else
1805  {
1806  WriteReferencingElement(n, ns, o, isNullable);
1807  }
1808  return;
1809  }
1810  bool flag = type != ambientType && !type.IsEnum;
1811  TypeEntry typeEntry2 = GetTypeEntry(type);
1812  if (typeEntry2 != null)
1813  {
1814  if (n == null)
1815  {
1816  WriteStartElement(typeEntry2.typeName, typeEntry2.typeNs, null, writePrefixed: true);
1817  }
1818  else
1819  {
1820  WriteStartElement(n, ns, null, writePrefixed: true);
1821  }
1822  if (flag)
1823  {
1824  WriteXsiType(typeEntry2.typeName, typeEntry2.typeNs);
1825  }
1826  typeEntry2.callback(o);
1827  w.WriteEndElement();
1828  }
1829  else
1830  {
1831  WriteTypedPrimitive(n, ns, o, flag);
1832  }
1833  }
1834 
1835  private void WriteReferencedElement(object o, Type ambientType)
1836  {
1837  WriteReferencedElement(null, null, o, ambientType);
1838  }
1839 
1840  private void WriteReferencedElement(string name, string ns, object o, Type ambientType)
1841  {
1842  if (name == null)
1843  {
1844  name = string.Empty;
1845  }
1846  Type type = o.GetType();
1847  if (type.IsArray || typeof(IEnumerable).IsAssignableFrom(type))
1848  {
1849  WriteArray(name, ns, o, type);
1850  return;
1851  }
1852  TypeEntry typeEntry = GetTypeEntry(type);
1853  if (typeEntry == null)
1854  {
1855  throw CreateUnknownTypeException(type);
1856  }
1857  WriteStartElement((name.Length == 0) ? typeEntry.typeName : name, (ns == null) ? typeEntry.typeNs : ns, null, writePrefixed: true);
1858  WriteId(o, addToReferencesList: false);
1859  if (ambientType != type)
1860  {
1861  WriteXsiType(typeEntry.typeName, typeEntry.typeNs);
1862  }
1863  typeEntry.callback(o);
1864  w.WriteEndElement();
1865  }
1866 
1867  private TypeEntry GetTypeEntry(Type t)
1868  {
1869  if (typeEntries == null)
1870  {
1871  typeEntries = new Hashtable();
1872  InitCallbacks();
1873  }
1874  return (TypeEntry)typeEntries[t];
1875  }
1876 
1878  protected abstract void InitCallbacks();
1879 
1881  protected void WriteReferencedElements()
1882  {
1883  if (referencesToWrite != null)
1884  {
1885  for (int i = 0; i < referencesToWrite.Count; i++)
1886  {
1887  WriteReferencedElement(referencesToWrite[i], null);
1888  }
1889  }
1890  }
1891 
1893  protected void TopLevelElement()
1894  {
1895  objectsInUse = new Hashtable();
1896  }
1897 
1901  {
1902  if (xmlns != null)
1903  {
1904  foreach (DictionaryEntry @namespace in xmlns.Namespaces)
1905  {
1906  string text = (string)@namespace.Key;
1907  string text2 = (string)@namespace.Value;
1908  if (namespaces != null)
1909  {
1910  string text3 = namespaces.Namespaces[text] as string;
1911  if (text3 != null && text3 != text2)
1912  {
1913  throw new InvalidOperationException(Res.GetString("XmlDuplicateNs", text, text2));
1914  }
1915  }
1916  string text4 = (text2 == null || text2.Length == 0) ? null : Writer.LookupPrefix(text2);
1917  if (text4 == null || text4 != text)
1918  {
1919  WriteAttribute("xmlns", text, null, text2);
1920  }
1921  }
1922  }
1923  namespaces = null;
1924  }
1925 
1926  private string NextPrefix()
1927  {
1928  if (usedPrefixes == null)
1929  {
1930  return aliasBase + ++tempNamespacePrefix;
1931  }
1932  while (usedPrefixes.ContainsKey(++tempNamespacePrefix))
1933  {
1934  }
1935  return aliasBase + tempNamespacePrefix;
1936  }
1937  }
1938 }
Converts a base data type to another base data type.
Definition: Convert.cs:10
abstract Type BaseType
Gets the type from which the current T:System.Type directly inherits.
Definition: Type.cs:180
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
void WriteElementQualifiedName(string localName, XmlQualifiedName value)
Writes an XML element with a specified qualified name in its body.
WriteState
Specifies the state of the T:System.Xml.XmlWriter.
Definition: WriteState.cs:5
void WriteElementStringRaw(string localName, string value)
Writes an XML element with a specified value in its body.
void WriteValue(string value)
Writes a specified string value.
Represents an XML document. You can use this class to load, validate, edit, add, and position XML in ...
Definition: XmlDocument.cs:13
void WriteStartElement(string name, string ns, object o, bool writePrefixed)
Writes an opening element tag, including any attributes.
static byte [] FromByteArrayBase64(byte[] value)
Processes a base-64 byte array.
abstract string LocalName
Gets the local name of the node, when overridden in a derived class.
Definition: XmlNode.cs:163
Exception CreateMismatchChoiceException(string value, string elementName, string enumValue)
Creates an T:System.InvalidOperationException that indicates that a value for an XML element does not...
void WriteElementLiteral(XmlNode node, string name, string ns, bool isNullable, bool any)
Instructs an T:System.Xml.XmlWriter object to write an T:System.Xml.XmlNode object within the body of...
void WriteElementQualifiedName(string localName, XmlQualifiedName value, XmlQualifiedName xsiType)
Writes an XML element with a specified qualified name in its body.
void WriteEndElement()
Writes a <closing> element tag.
bool EscapeName
Gets or sets a value that indicates whether the M:System.Xml.XmlConvert.EncodeName(System....
ArrayList Namespaces
Gets or sets a list of XML qualified name objects that contain the namespaces and prefixes used to pr...
Contains the XML namespaces and prefixes that the T:System.Xml.Serialization.XmlSerializer uses to ge...
virtual void Add(object key, object value)
Adds an element with the specified key and value into the T:System.Collections.Hashtable.
Definition: Hashtable.cs:916
bool MoveNext()
Advances the enumerator to the next element of the collection.
void WriteElementStringRaw(string localName, string ns, byte[] value)
Writes an XML element with a specified value in its body.
void WriteAttribute(string prefix, string localName, string ns, string value)
Writes an XML attribute where the namespace prefix is provided manually.
void WriteStartElement(string name)
Writes an opening element tag, including any attributes.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static TypeCode GetTypeCode(Type type)
Gets the underlying type code of the specified T:System.Type.
Definition: Type.cs:1199
static string FromXmlNmToken(string nmToken)
Encodes an XML name.
void WriteNullableStringEncodedRaw(string name, string ns, string value, XmlQualifiedName xsiType)
Writes an XML element that contains a string as the body. T:System.Xml.XmlWriter inserts an xsi:nil='...
void WriteNamespaceDeclarations(XmlSerializerNamespaces xmlns)
Writes the namespace declaration attributes.
void WriteNullTagEncoded(string name)
Writes an XML element with an xsi:nil='true' attribute.
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
Definition: Type.cs:153
abstract void WriteStartDocument()
When overridden in a derived class, writes the XML declaration with the version "1....
abstract void WriteTo(XmlWriter w)
Saves the current node to the specified T:System.Xml.XmlWriter, when overridden in a derived class.
void WriteAttribute(string localName, string ns, byte[] value)
Instructs an T:System.Xml.XmlWriter object to write an XML attribute.
void WriteNullableStringEncodedRaw(string name, string ns, byte[] value, XmlQualifiedName xsiType)
Writes a byte array as the body of an XML element. T:System.Xml.XmlWriter inserts an xsi:nil='true' a...
delegate void XmlSerializationWriteCallback(object o)
Delegate that is used by the T:System.Xml.Serialization.XmlSerializer class for serialization of type...
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
string FromXmlQualifiedName(XmlQualifiedName xmlQualifiedName, bool ignoreEmpty)
Produces a string that can be written as an XML qualified name, with invalid characters replaced by e...
void WriteStartElement(string name, string ns, bool writePrefixed)
Writes an opening element tag, including any attributes.
TypeCode
Specifies the type of an object.
Definition: TypeCode.cs:9
static string FromXmlNmTokens(string nmTokens)
Encodes a space-delimited sequence of XML names into a single XML name.
static string FromTime(DateTime value)
Produces a string from a T:System.DateTime object.
void WriteStartDocument()
Writes the XML declaration if the writer is positioned at the start of an XML document.
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
void WriteAttribute(string localName, string ns, string value)
Writes an XML attribute.
void WriteEmptyTag(string name)
Writes an XML element whose body is empty.
Definition: __Canon.cs:3
Represents the root class for the Xml schema object model hierarchy and serves as a base class for cl...
static string FromByteArrayHex(byte[] value)
Produces a string from an input hexadecimal byte array.
Represents an attribute. Valid and default values for the attribute are defined in a document type de...
Definition: XmlAttribute.cs:7
abstract void WriteEndAttribute()
When overridden in a derived class, closes the previous M:System.Xml.XmlWriter.WriteStartAttribute(Sy...
static string ToString(bool value)
Converts the T:System.Boolean to a T:System.String.
Definition: XmlConvert.cs:601
void WriteStartAttribute(string localName, string ns)
Writes the start of an attribute with the specified local name and namespace URI.
Definition: XmlWriter.cs:199
Represents an abstract class used for controlling serialization by the T:System.Xml....
void WriteXmlAttribute(XmlNode node, object container)
Writes the specified T:System.Xml.XmlNode object as an XML attribute.
static string EncodeLocalName(string name)
Converts the name to a valid XML local name.
Definition: XmlConvert.cs:72
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
void WriteReferencingElement(string n, string ns, object o, bool isNullable)
Writes a SOAP message XML element that contains a reference to a multiRef element for a given object.
void WriteTypedPrimitive(string name, string ns, object o, bool xsiType)
Writes an XML element whose text body is a value of a simple XML Schema data type.
abstract void WriteString(string text)
When overridden in a derived class, writes the given text content.
void WriteElementQualifiedName(string localName, string ns, XmlQualifiedName value)
Writes an XML element with a specified qualified name in its body.
virtual bool ContainsKey(object key)
Determines whether the T:System.Collections.Hashtable contains a specific key.
Definition: Hashtable.cs:983
void WriteNullableStringEncoded(string name, string ns, string value, XmlQualifiedName xsiType)
Writes an XML element that contains a string as the body. T:System.Xml.XmlWriter inserts an xsi:nil='...
virtual bool IsEnum
Gets a value indicating whether the current T:System.Type represents an enumeration.
Definition: Type.cs:484
void WriteElementEncoded(XmlNode node, string name, string ns, bool isNullable, bool any)
Writes an XML node object within the body of a named XML element.
virtual string NamespaceURI
Gets the namespace URI of this node.
Definition: XmlNode.cs:143
string Namespace
Gets a string representation of the namespace of the T:System.Xml.XmlQualifiedName.
void WriteXsiType(string name, string ns)
Writes an xsi:type attribute for an XML element that is being serialized into a document.
void WritePotentiallyReferencingElement(string n, string ns, object o)
Writes a SOAP message XML element that can contain a reference to a <multiRef> XML element for a give...
abstract string LookupPrefix(string ns)
When overridden in a derived class, returns the closest prefix defined in the current namespace scope...
void WriteReferencingElement(string n, string ns, object o)
Writes a SOAP message XML element that contains a reference to a multiRef element for a given object.
Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files t...
Definition: XmlWriter.cs:12
void AddWriteCallback(Type type, string typeName, string typeNs, XmlSerializationWriteCallback callback)
Stores an implementation of the T:System.Xml.Serialization.XmlSerializationWriteCallback delegate and...
Exception CreateUnknownAnyElementException(string name, string ns)
Creates an T:System.InvalidOperationException that indicates that an XML element that should adhere t...
void WriteNullableStringLiteral(string name, string ns, string value)
Writes an XML element that contains a string as the body. T:System.Xml.XmlWriter inserts an xsi:nil='...
override string NamespaceURI
Gets the namespace URI of this node.
Definition: XmlAttribute.cs:41
Exception CreateInvalidEnumValueException(object value, string typeName)
Creates an T:System.InvalidOperationException for an invalid enumeration value.
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
void WriteSerializable(IXmlSerializable serializable, string name, string ns, bool isNullable)
Writes an object that uses custom XML formatting as an XML element.
bool IsArray
Gets a value that indicates whether the type is an array.
Definition: Type.cs:551
abstract void InitCallbacks()
Initializes an instances of the T:System.Xml.Serialization.XmlSerializationWriteCallback delegate to ...
void WriteReferencedElements()
Serializes objects into SOAP-encoded multiRef XML elements in a SOAP message.
string Name
Gets a string representation of the qualified name of the T:System.Xml.XmlQualifiedName.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
void WriteElementString(string localName, string value)
Writes an XML element with a specified value in its body.
XmlWriter Writer
Gets or sets the T:System.Xml.XmlWriter that is being used by the T:System.Xml.Serialization....
static string FromDate(DateTime value)
Produces a string from a T:System.DateTime object.
void WriteNullableQualifiedNameEncoded(string name, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
Writes an XML element whose body contains a valid XML qualified name. T:System.Xml....
string FromXmlQualifiedName(XmlQualifiedName xmlQualifiedName)
Returns an XML qualified name, with invalid characters replaced by escape sequences.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
Definition: Hashtable.cs:17
virtual ICollection Keys
Gets an T:System.Collections.ICollection containing the keys in the T:System.Collections....
Definition: Hashtable.cs:617
void WriteElementStringRaw(string localName, string value, XmlQualifiedName xsiType)
Writes an XML element with a specified value in its body.
void WriteRpcResult(string name, string ns)
Writes a SOAP 1.2 RPC result element with a specified qualified name in its body.
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
void WriteXml(XmlWriter writer)
Converts an object into its XML representation.
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
void WriteNullableStringLiteralRaw(string name, string ns, string value)
Writes an XML element that contains a string as the body. T:System.Xml.XmlWriter inserts a xsi:nil='t...
void WriteStartElement(string name, string ns, object o)
Writes an opening element tag, including any attributes.
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Exception CreateInvalidAnyTypeException(object o)
Creates an T:System.InvalidOperationException that indicates the T:System.Xml.Serialization....
void WriteNullTagLiteral(string name)
Writes an XML element with an xsi:nil='true' attribute.
abstract void WriteEndElement()
When overridden in a derived class, closes one element and pops the corresponding namespace scope.
Represents an XML qualified name.
void WriteAttributeString(string localName, string ns, string value)
When overridden in a derived class, writes an attribute with the specified local name,...
Definition: XmlWriter.cs:155
void WriteStartElement(string name, string ns, object o, bool writePrefixed, XmlSerializerNamespaces xmlns)
Writes an opening element tag, including any attributes.
void WriteAttribute(string localName, string value)
Instructs the T:System.Xml.XmlWriter to write an XML attribute that has no namespace specified for it...
void WriteElementStringRaw(string localName, string ns, byte[] value, XmlQualifiedName xsiType)
Writes an XML element with a specified value in its body.
static TypeCode GetTypeCode(object value)
Returns the T:System.TypeCode for the specified object.
Definition: Convert.cs:115
void WriteElementStringRaw(string localName, string ns, string value, XmlQualifiedName xsiType)
Writes an XML element with a specified value in its body.
void WriteEmptyTag(string name, string ns)
Writes an XML element whose body is empty.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
static string FromDateTime(DateTime value)
Produces a string from an input T:System.DateTime.
static string FromXmlName(string name)
Encodes a valid XML name by replacing characters that are not valid with escape sequences.
void WriteId(object o)
Writes an id attribute that appears in a SOAP-encoded multiRef element.
void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference, bool isNullable)
Writes a SOAP message XML element that can contain a reference to a multiRef XML element for a given ...
void WriteSerializable(IXmlSerializable serializable, string name, string ns, bool isNullable, bool wrapped)
Instructs T:System.Xml.XmlNode to write an object that uses custom XML formatting as an XML element.
abstract void WriteRaw(char[] buffer, int index, int count)
When overridden in a derived class, writes raw markup manually from a character buffer.
override string LocalName
Gets the local name of the node.
Definition: XmlAttribute.cs:37
void WriteElementStringRaw(string localName, byte[] value, XmlQualifiedName xsiType)
Writes an XML element with a specified value in its body.
static Assembly ResolveDynamicAssembly(string assemblyFullName)
Gets a dynamically generated assembly by name.
static string FromEnum(long value, string[] values, long[] ids, string typeName)
Takes a numeric enumeration value and the names and constants from the enumerator list for the enumer...
void WriteElementStringRaw(string localName, string ns, string value)
Writes an XML element with a specified value in its body.
void TopLevelElement()
Initializes object references only while serializing a SOAP-encoded SOAP message.
void WriteValue(byte[] value)
Writes a base-64 byte array.
virtual bool Contains(object key)
Determines whether the T:System.Collections.Hashtable contains a specific key.
Definition: Hashtable.cs:972
void WriteNullTagLiteral(string name, string ns)
Writes an XML element with an xsi:nil='true' attribute.
void WriteXmlAttribute(XmlNode node)
Writes the specified T:System.Xml.XmlNode as an XML attribute.
void WriteElementString(string localName, string ns, string value, XmlQualifiedName xsiType)
Writes an XML element with a specified value in its body.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
virtual void Remove(object key)
Removes the element with the specified key from the T:System.Collections.Hashtable.
Definition: Hashtable.cs:1349
void WriteNullTagEncoded(string name, string ns)
Writes an XML element with an xsi:nil='true' attribute.
Exception CreateUnknownTypeException(Type type)
Creates an T:System.InvalidOperationException that indicates that a type being serialized is not bein...
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
void WriteElementStringRaw(string localName, byte[] value)
Writes an XML element with a specified value in its body.
Exception CreateInvalidChoiceIdentifierValueException(string type, string identifier)
Creates an T:System.InvalidOperationException that indicates a failure while writing an array where a...
void WriteAttribute(string localName, byte[] value)
Instructs an T:System.Xml.XmlWriter object to write an XML attribute that has no namespace specified ...
static string FromChar(char value)
Produces a string from an input T:System.Char.
The exception that is thrown when a method call is invalid for the object's current state.
static Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Gets the T:System.Type with the specified name, specifying whether to throw an exception if the type ...
Definition: Type.cs:853
static string FromEnum(long value, string[] values, long[] ids)
Produces a string that consists of delimited identifiers that represent the enumeration members that ...
Exception CreateChoiceIdentifierValueException(string value, string identifier, string name, string ns)
Creates an T:System.InvalidOperationException that indicates an unexpected name for an element that a...
static string FromXmlNCName(string ncName)
Encodes a valid XML local name by replacing characters that are not valid with escape sequences.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
override string Value
Gets or sets the value of the node.
Definition: XmlAttribute.cs:71
void WriteNullableQualifiedNameLiteral(string name, string ns, XmlQualifiedName value)
Writes an XML element whose body contains a valid XML qualified name. T:System.Xml....
An abstract class that is the base class for T:System.Xml.Serialization.XmlSerializationReader and T:...
void WriteNullableStringLiteralRaw(string name, string ns, byte[] value)
Writes a byte array as the body of an XML element. T:System.Xml.XmlWriter inserts an xsi:nil='true' a...
Defines a dictionary key/value pair that can be set or retrieved.
override string Name
Gets the qualified name of the node.
Definition: XmlAttribute.cs:33
void WriteElementString(string localName, string ns, string value)
Writes an XML element with a specified value in its body.
bool IsEmpty
Gets a value indicating whether the T:System.Xml.XmlQualifiedName is empty.
void WriteStartElement(string name, string ns)
Writes an opening element tag, including any attributes.
Exception CreateUnknownTypeException(object o)
Creates an T:System.InvalidOperationException that indicates that a type being serialized is not bein...
Provides custom formatting for XML serialization and deserialization.
void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType)
Writes a SOAP message XML element that can contain a reference to a <multiRef> XML element for a give...
abstract WriteState WriteState
When overridden in a derived class, gets the state of the writer.
Definition: XmlWriter.cs:36
void WritePotentiallyReferencingElement(string n, string ns, object o, Type ambientType, bool suppressReference)
Writes a SOAP message XML element that can contain a reference to a <multiRef> XML element for a give...
Represents a single node in the XML document.
Definition: XmlNode.cs:13
Exception CreateInvalidAnyTypeException(Type type)
Creates an T:System.InvalidOperationException that indicates the T:System.Xml.Serialization....
void WriteElementString(string localName, string value, XmlQualifiedName xsiType)
Writes an XML element with a specified value in its body.
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
void WriteElementString(string localName, string value)
Writes an element with the specified local name and value.
Definition: XmlWriter.cs:769
virtual int Count
Gets the number of key/value pairs contained in the T:System.Collections.Hashtable.
Definition: Hashtable.cs:658
void WriteElementQualifiedName(string localName, string ns, XmlQualifiedName value, XmlQualifiedName xsiType)
Writes an XML element with a specified qualified name in its body.
Encodes and decodes XML names, and provides methods for converting between common language runtime ty...
Definition: XmlConvert.cs:11
void WriteStartElement(string localName, string ns)
When overridden in a derived class, writes the specified start tag and associates it with the given n...
Definition: XmlWriter.cs:110
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14
void WriteEndElement(object o)
Writes a <closing> element tag.