mscorlib(4.0.0.0) API with additions
XmlConvert.cs
1 using System.Collections;
3 using System.Text;
5 using System.Xml.Schema;
6 
7 namespace System.Xml
8 {
10  [global::__DynamicallyInvokable]
11  public class XmlConvert
12  {
13  private static XmlCharType xmlCharType = XmlCharType.Instance;
14 
15  internal static char[] crt = new char[3]
16  {
17  '\n',
18  '\r',
19  '\t'
20  };
21 
22  private static readonly int c_EncodedCharLength = 7;
23 
24  private static volatile Regex c_EncodeCharPattern;
25 
26  private static volatile Regex c_DecodeCharPattern;
27 
28  private static volatile string[] s_allDateTimeFormats;
29 
30  internal static readonly char[] WhitespaceChars = new char[4]
31  {
32  ' ',
33  '\t',
34  '\n',
35  '\r'
36  };
37 
38  private static string[] AllDateTimeFormats
39  {
40  get
41  {
42  if (s_allDateTimeFormats == null)
43  {
44  CreateAllDateTimeFormats();
45  }
46  return s_allDateTimeFormats;
47  }
48  }
49 
53  [global::__DynamicallyInvokable]
54  public static string EncodeName(string name)
55  {
56  return EncodeName(name, first: true, local: false);
57  }
58 
62  [global::__DynamicallyInvokable]
63  public static string EncodeNmToken(string name)
64  {
65  return EncodeName(name, first: false, local: false);
66  }
67 
71  [global::__DynamicallyInvokable]
72  public static string EncodeLocalName(string name)
73  {
74  return EncodeName(name, first: true, local: true);
75  }
76 
80  [global::__DynamicallyInvokable]
81  public static string DecodeName(string name)
82  {
83  if (name == null || name.Length == 0)
84  {
85  return name;
86  }
87  StringBuilder stringBuilder = null;
88  int length = name.Length;
89  int num = 0;
90  int num2 = name.IndexOf('_');
91  MatchCollection matchCollection = null;
92  IEnumerator enumerator = null;
93  if (num2 >= 0)
94  {
95  if (c_DecodeCharPattern == null)
96  {
97  c_DecodeCharPattern = new Regex("_[Xx]([0-9a-fA-F]{4}|[0-9a-fA-F]{8})_");
98  }
99  matchCollection = c_DecodeCharPattern.Matches(name, num2);
100  enumerator = matchCollection.GetEnumerator();
101  int num3 = -1;
102  if (enumerator != null && enumerator.MoveNext())
103  {
104  Match match = (Match)enumerator.Current;
105  num3 = match.Index;
106  }
107  for (int i = 0; i < length - c_EncodedCharLength + 1; i++)
108  {
109  if (i != num3)
110  {
111  continue;
112  }
113  if (enumerator.MoveNext())
114  {
115  Match match2 = (Match)enumerator.Current;
116  num3 = match2.Index;
117  }
118  if (stringBuilder == null)
119  {
120  stringBuilder = new StringBuilder(length + 20);
121  }
122  stringBuilder.Append(name, num, i - num);
123  if (name[i + 6] != '_')
124  {
125  int num4 = FromHex(name[i + 2]) * 268435456 + FromHex(name[i + 3]) * 16777216 + FromHex(name[i + 4]) * 1048576 + FromHex(name[i + 5]) * 65536 + FromHex(name[i + 6]) * 4096 + FromHex(name[i + 7]) * 256 + FromHex(name[i + 8]) * 16 + FromHex(name[i + 9]);
126  if (num4 >= 65536)
127  {
128  if (num4 <= 1114111)
129  {
130  num = i + c_EncodedCharLength + 4;
131  XmlCharType.SplitSurrogateChar(num4, out char lowChar, out char highChar);
132  stringBuilder.Append(highChar);
133  stringBuilder.Append(lowChar);
134  }
135  }
136  else
137  {
138  num = i + c_EncodedCharLength + 4;
139  stringBuilder.Append((char)num4);
140  }
141  i += c_EncodedCharLength - 1 + 4;
142  }
143  else
144  {
145  num = i + c_EncodedCharLength;
146  stringBuilder.Append((char)(FromHex(name[i + 2]) * 4096 + FromHex(name[i + 3]) * 256 + FromHex(name[i + 4]) * 16 + FromHex(name[i + 5])));
147  i += c_EncodedCharLength - 1;
148  }
149  }
150  if (num == 0)
151  {
152  return name;
153  }
154  if (num < length)
155  {
156  stringBuilder.Append(name, num, length - num);
157  }
158  return stringBuilder.ToString();
159  }
160  return name;
161  }
162 
163  private static string EncodeName(string name, bool first, bool local)
164  {
165  if (string.IsNullOrEmpty(name))
166  {
167  return name;
168  }
169  StringBuilder stringBuilder = null;
170  int length = name.Length;
171  int num = 0;
172  int i = 0;
173  int num2 = name.IndexOf('_');
174  MatchCollection matchCollection = null;
175  IEnumerator enumerator = null;
176  if (num2 >= 0)
177  {
178  if (c_EncodeCharPattern == null)
179  {
180  c_EncodeCharPattern = new Regex("(?<=_)[Xx]([0-9a-fA-F]{4}|[0-9a-fA-F]{8})_");
181  }
182  matchCollection = c_EncodeCharPattern.Matches(name, num2);
183  enumerator = matchCollection.GetEnumerator();
184  }
185  int num3 = -1;
186  if (enumerator != null && enumerator.MoveNext())
187  {
188  Match match = (Match)enumerator.Current;
189  num3 = match.Index - 1;
190  }
191  if (first && ((!xmlCharType.IsStartNCNameCharXml4e(name[0]) && (local || (!local && name[0] != ':'))) || num3 == 0))
192  {
193  if (stringBuilder == null)
194  {
195  stringBuilder = new StringBuilder(length + 20);
196  }
197  stringBuilder.Append("_x");
198  if (length > 1 && XmlCharType.IsHighSurrogate(name[0]) && XmlCharType.IsLowSurrogate(name[1]))
199  {
200  int highChar = name[0];
201  int lowChar = name[1];
202  stringBuilder.Append(XmlCharType.CombineSurrogateChar(lowChar, highChar).ToString("X8", CultureInfo.InvariantCulture));
203  i++;
204  num = 2;
205  }
206  else
207  {
208  stringBuilder.Append(((int)name[0]).ToString("X4", CultureInfo.InvariantCulture));
209  num = 1;
210  }
211  stringBuilder.Append("_");
212  i++;
213  if (num3 == 0 && enumerator.MoveNext())
214  {
215  Match match2 = (Match)enumerator.Current;
216  num3 = match2.Index - 1;
217  }
218  }
219  for (; i < length; i++)
220  {
221  if ((local && !xmlCharType.IsNCNameCharXml4e(name[i])) || (!local && !xmlCharType.IsNameCharXml4e(name[i])) || num3 == i)
222  {
223  if (stringBuilder == null)
224  {
225  stringBuilder = new StringBuilder(length + 20);
226  }
227  if (num3 == i && enumerator.MoveNext())
228  {
229  Match match3 = (Match)enumerator.Current;
230  num3 = match3.Index - 1;
231  }
232  stringBuilder.Append(name, num, i - num);
233  stringBuilder.Append("_x");
234  if (length > i + 1 && XmlCharType.IsHighSurrogate(name[i]) && XmlCharType.IsLowSurrogate(name[i + 1]))
235  {
236  int highChar2 = name[i];
237  int lowChar2 = name[i + 1];
238  stringBuilder.Append(XmlCharType.CombineSurrogateChar(lowChar2, highChar2).ToString("X8", CultureInfo.InvariantCulture));
239  num = i + 2;
240  i++;
241  }
242  else
243  {
244  stringBuilder.Append(((int)name[i]).ToString("X4", CultureInfo.InvariantCulture));
245  num = i + 1;
246  }
247  stringBuilder.Append("_");
248  }
249  }
250  if (num == 0)
251  {
252  return name;
253  }
254  if (num < length)
255  {
256  stringBuilder.Append(name, num, length - num);
257  }
258  return stringBuilder.ToString();
259  }
260 
261  private static int FromHex(char digit)
262  {
263  if (digit > '9')
264  {
265  return ((digit <= 'F') ? (digit - 65) : (digit - 97)) + 10;
266  }
267  return digit - 48;
268  }
269 
270  internal static byte[] FromBinHexString(string s)
271  {
272  return FromBinHexString(s, allowOddCount: true);
273  }
274 
275  internal static byte[] FromBinHexString(string s, bool allowOddCount)
276  {
277  if (s == null)
278  {
279  throw new ArgumentNullException("s");
280  }
281  return BinHexDecoder.Decode(s.ToCharArray(), allowOddCount);
282  }
283 
284  internal static string ToBinHexString(byte[] inArray)
285  {
286  if (inArray == null)
287  {
288  throw new ArgumentNullException("inArray");
289  }
290  return BinHexEncoder.Encode(inArray, 0, inArray.Length);
291  }
292 
300  [global::__DynamicallyInvokable]
301  public static string VerifyName(string name)
302  {
303  if (name == null)
304  {
305  throw new ArgumentNullException("name");
306  }
307  if (name.Length == 0)
308  {
309  throw new ArgumentNullException("name", Res.GetString("Xml_EmptyName"));
310  }
311  int num = ValidateNames.ParseNameNoNamespaces(name, 0);
312  if (num != name.Length)
313  {
314  throw CreateInvalidNameCharException(name, num, ExceptionType.XmlException);
315  }
316  return name;
317  }
318 
319  internal static Exception TryVerifyName(string name)
320  {
321  if (name == null || name.Length == 0)
322  {
323  return new XmlException("Xml_EmptyName", string.Empty);
324  }
325  int num = ValidateNames.ParseNameNoNamespaces(name, 0);
326  if (num != name.Length)
327  {
328  return new XmlException((num == 0) ? "Xml_BadStartNameChar" : "Xml_BadNameChar", XmlException.BuildCharExceptionArgs(name, num));
329  }
330  return null;
331  }
332 
333  internal static string VerifyQName(string name)
334  {
335  return VerifyQName(name, ExceptionType.XmlException);
336  }
337 
338  internal static string VerifyQName(string name, ExceptionType exceptionType)
339  {
340  if (name == null || name.Length == 0)
341  {
342  throw new ArgumentNullException("name");
343  }
344  int colonOffset = -1;
345  int num = ValidateNames.ParseQName(name, 0, out colonOffset);
346  if (num != name.Length)
347  {
348  throw CreateException("Xml_BadNameChar", XmlException.BuildCharExceptionArgs(name, num), exceptionType, 0, num + 1);
349  }
350  return name;
351  }
352 
360  [global::__DynamicallyInvokable]
361  public static string VerifyNCName(string name)
362  {
363  return VerifyNCName(name, ExceptionType.XmlException);
364  }
365 
366  internal static string VerifyNCName(string name, ExceptionType exceptionType)
367  {
368  if (name == null)
369  {
370  throw new ArgumentNullException("name");
371  }
372  if (name.Length == 0)
373  {
374  throw new ArgumentNullException("name", Res.GetString("Xml_EmptyLocalName"));
375  }
376  int num = ValidateNames.ParseNCName(name, 0);
377  if (num != name.Length)
378  {
379  throw CreateInvalidNameCharException(name, num, exceptionType);
380  }
381  return name;
382  }
383 
384  internal static Exception TryVerifyNCName(string name)
385  {
386  int num = ValidateNames.ParseNCName(name);
387  if (num == 0 || num != name.Length)
388  {
389  return ValidateNames.GetInvalidNameException(name, 0, num);
390  }
391  return null;
392  }
393 
398  public static string VerifyTOKEN(string token)
399  {
400  if (token == null || token.Length == 0)
401  {
402  return token;
403  }
404  if (token[0] == ' ' || token[token.Length - 1] == ' ' || token.IndexOfAny(crt) != -1 || token.IndexOf(" ", StringComparison.Ordinal) != -1)
405  {
406  throw new XmlException("Sch_NotTokenString", token);
407  }
408  return token;
409  }
410 
411  internal static Exception TryVerifyTOKEN(string token)
412  {
413  if (token == null || token.Length == 0)
414  {
415  return null;
416  }
417  if (token[0] == ' ' || token[token.Length - 1] == ' ' || token.IndexOfAny(crt) != -1 || token.IndexOf(" ", StringComparison.Ordinal) != -1)
418  {
419  return new XmlException("Sch_NotTokenString", token);
420  }
421  return null;
422  }
423 
430  [global::__DynamicallyInvokable]
431  public static string VerifyNMTOKEN(string name)
432  {
433  return VerifyNMTOKEN(name, ExceptionType.XmlException);
434  }
435 
436  internal static string VerifyNMTOKEN(string name, ExceptionType exceptionType)
437  {
438  if (name == null)
439  {
440  throw new ArgumentNullException("name");
441  }
442  if (name.Length == 0)
443  {
444  throw CreateException("Xml_InvalidNmToken", name, exceptionType);
445  }
446  int num = ValidateNames.ParseNmtokenNoNamespaces(name, 0);
447  if (num != name.Length)
448  {
449  throw CreateException("Xml_BadNameChar", XmlException.BuildCharExceptionArgs(name, num), exceptionType, 0, num + 1);
450  }
451  return name;
452  }
453 
454  internal static Exception TryVerifyNMTOKEN(string name)
455  {
456  if (name == null || name.Length == 0)
457  {
458  return new XmlException("Xml_EmptyName", string.Empty);
459  }
460  int num = ValidateNames.ParseNmtokenNoNamespaces(name, 0);
461  if (num != name.Length)
462  {
463  return new XmlException("Xml_BadNameChar", XmlException.BuildCharExceptionArgs(name, num));
464  }
465  return null;
466  }
467 
468  internal static string VerifyNormalizedString(string str)
469  {
470  if (str.IndexOfAny(crt) != -1)
471  {
472  throw new XmlSchemaException("Sch_NotNormalizedString", str);
473  }
474  return str;
475  }
476 
477  internal static Exception TryVerifyNormalizedString(string str)
478  {
479  if (str.IndexOfAny(crt) != -1)
480  {
481  return new XmlSchemaException("Sch_NotNormalizedString", str);
482  }
483  return null;
484  }
485 
490  [global::__DynamicallyInvokable]
491  public static string VerifyXmlChars(string content)
492  {
493  if (content == null)
494  {
495  throw new ArgumentNullException("content");
496  }
497  VerifyCharData(content, ExceptionType.XmlException);
498  return content;
499  }
500 
505  [global::__DynamicallyInvokable]
506  public static string VerifyPublicId(string publicId)
507  {
508  if (publicId == null)
509  {
510  throw new ArgumentNullException("publicId");
511  }
512  int num = xmlCharType.IsPublicId(publicId);
513  if (num != -1)
514  {
515  throw CreateInvalidCharException(publicId, num, ExceptionType.XmlException);
516  }
517  return publicId;
518  }
519 
524  [global::__DynamicallyInvokable]
525  public static string VerifyWhitespace(string content)
526  {
527  if (content == null)
528  {
529  throw new ArgumentNullException("content");
530  }
531  int num = xmlCharType.IsOnlyWhitespaceWithPos(content);
532  if (num != -1)
533  {
534  throw new XmlException("Xml_InvalidWhitespaceCharacter", XmlException.BuildCharExceptionArgs(content, num), 0, num + 1);
535  }
536  return content;
537  }
538 
543  public unsafe static bool IsStartNCNameChar(char ch)
544  {
545  return (xmlCharType.charProperties[(int)ch] & 4) != 0;
546  }
547 
551  public unsafe static bool IsNCNameChar(char ch)
552  {
553  return (xmlCharType.charProperties[(int)ch] & 8) != 0;
554  }
555 
560  public unsafe static bool IsXmlChar(char ch)
561  {
562  return (xmlCharType.charProperties[(int)ch] & 0x10) != 0;
563  }
564 
570  public static bool IsXmlSurrogatePair(char lowChar, char highChar)
571  {
572  if (XmlCharType.IsHighSurrogate(highChar))
573  {
574  return XmlCharType.IsLowSurrogate(lowChar);
575  }
576  return false;
577  }
578 
583  public static bool IsPublicIdChar(char ch)
584  {
585  return xmlCharType.IsPubidChar(ch);
586  }
587 
592  public unsafe static bool IsWhitespaceChar(char ch)
593  {
594  return (xmlCharType.charProperties[(int)ch] & 1) != 0;
595  }
596 
600  [global::__DynamicallyInvokable]
601  public static string ToString(bool value)
602  {
603  if (!value)
604  {
605  return "false";
606  }
607  return "true";
608  }
609 
613  [global::__DynamicallyInvokable]
614  public static string ToString(char value)
615  {
616  return value.ToString(null);
617  }
618 
622  [global::__DynamicallyInvokable]
623  public static string ToString(decimal value)
624  {
625  return value.ToString(null, NumberFormatInfo.InvariantInfo);
626  }
627 
631  [CLSCompliant(false)]
632  [global::__DynamicallyInvokable]
633  public static string ToString(sbyte value)
634  {
635  return value.ToString(null, NumberFormatInfo.InvariantInfo);
636  }
637 
641  [global::__DynamicallyInvokable]
642  public static string ToString(short value)
643  {
644  return value.ToString(null, NumberFormatInfo.InvariantInfo);
645  }
646 
650  [global::__DynamicallyInvokable]
651  public static string ToString(int value)
652  {
653  return value.ToString(null, NumberFormatInfo.InvariantInfo);
654  }
655 
659  [global::__DynamicallyInvokable]
660  public static string ToString(long value)
661  {
662  return value.ToString(null, NumberFormatInfo.InvariantInfo);
663  }
664 
668  [global::__DynamicallyInvokable]
669  public static string ToString(byte value)
670  {
671  return value.ToString(null, NumberFormatInfo.InvariantInfo);
672  }
673 
677  [CLSCompliant(false)]
678  [global::__DynamicallyInvokable]
679  public static string ToString(ushort value)
680  {
681  return value.ToString(null, NumberFormatInfo.InvariantInfo);
682  }
683 
687  [CLSCompliant(false)]
688  [global::__DynamicallyInvokable]
689  public static string ToString(uint value)
690  {
691  return value.ToString(null, NumberFormatInfo.InvariantInfo);
692  }
693 
697  [CLSCompliant(false)]
698  [global::__DynamicallyInvokable]
699  public static string ToString(ulong value)
700  {
701  return value.ToString(null, NumberFormatInfo.InvariantInfo);
702  }
703 
707  [global::__DynamicallyInvokable]
708  public static string ToString(float value)
709  {
710  if (float.IsNegativeInfinity(value))
711  {
712  return "-INF";
713  }
714  if (float.IsPositiveInfinity(value))
715  {
716  return "INF";
717  }
718  if (IsNegativeZero(value))
719  {
720  return "-0";
721  }
722  return value.ToString("R", NumberFormatInfo.InvariantInfo);
723  }
724 
728  [global::__DynamicallyInvokable]
729  public static string ToString(double value)
730  {
731  if (double.IsNegativeInfinity(value))
732  {
733  return "-INF";
734  }
735  if (double.IsPositiveInfinity(value))
736  {
737  return "INF";
738  }
739  if (IsNegativeZero(value))
740  {
741  return "-0";
742  }
743  return value.ToString("R", NumberFormatInfo.InvariantInfo);
744  }
745 
749  [global::__DynamicallyInvokable]
750  public static string ToString(TimeSpan value)
751  {
752  return new XsdDuration(value).ToString();
753  }
754 
758  [Obsolete("Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode")]
759  public static string ToString(DateTime value)
760  {
761  return ToString(value, "yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz");
762  }
763 
768  public static string ToString(DateTime value, string format)
769  {
770  return value.ToString(format, DateTimeFormatInfo.InvariantInfo);
771  }
772 
779  [global::__DynamicallyInvokable]
780  public static string ToString(DateTime value, XmlDateTimeSerializationMode dateTimeOption)
781  {
782  switch (dateTimeOption)
783  {
784  case XmlDateTimeSerializationMode.Local:
785  value = SwitchToLocalTime(value);
786  break;
788  value = SwitchToUtcTime(value);
789  break;
790  case XmlDateTimeSerializationMode.Unspecified:
791  value = new DateTime(value.Ticks, DateTimeKind.Unspecified);
792  break;
793  default:
794  throw new ArgumentException(Res.GetString("Sch_InvalidDateTimeOption", dateTimeOption, "dateTimeOption"));
795  case XmlDateTimeSerializationMode.RoundtripKind:
796  break;
797  }
798  return new XsdDateTime(value, XsdDateTimeFlags.DateTime).ToString();
799  }
800 
804  [global::__DynamicallyInvokable]
805  public static string ToString(DateTimeOffset value)
806  {
807  return new XsdDateTime(value).ToString();
808  }
809 
814  [global::__DynamicallyInvokable]
815  public static string ToString(DateTimeOffset value, string format)
816  {
817  return value.ToString(format, DateTimeFormatInfo.InvariantInfo);
818  }
819 
823  [global::__DynamicallyInvokable]
824  public static string ToString(Guid value)
825  {
826  return value.ToString();
827  }
828 
836  [global::__DynamicallyInvokable]
837  public static bool ToBoolean(string s)
838  {
839  s = TrimString(s);
840  switch (s)
841  {
842  case "1":
843  case "true":
844  return true;
845  case "0":
846  case "false":
847  return false;
848  default:
849  throw new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Boolean"));
850  }
851  }
852 
853  internal static Exception TryToBoolean(string s, out bool result)
854  {
855  s = TrimString(s);
856  switch (s)
857  {
858  case "0":
859  case "false":
860  result = false;
861  return null;
862  case "1":
863  case "true":
864  result = true;
865  return null;
866  default:
867  result = false;
868  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Boolean"));
869  }
870  }
871 
877  [global::__DynamicallyInvokable]
878  public static char ToChar(string s)
879  {
880  if (s == null)
881  {
882  throw new ArgumentNullException("s");
883  }
884  if (s.Length != 1)
885  {
886  throw new FormatException(Res.GetString("XmlConvert_NotOneCharString"));
887  }
888  return s[0];
889  }
890 
891  internal static Exception TryToChar(string s, out char result)
892  {
893  if (!char.TryParse(s, out result))
894  {
895  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Char"));
896  }
897  return null;
898  }
899 
909  [global::__DynamicallyInvokable]
910  public static decimal ToDecimal(string s)
911  {
912  return decimal.Parse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, NumberFormatInfo.InvariantInfo);
913  }
914 
915  internal static Exception TryToDecimal(string s, out decimal result)
916  {
917  if (!decimal.TryParse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, NumberFormatInfo.InvariantInfo, out result))
918  {
919  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Decimal"));
920  }
921  return null;
922  }
923 
924  internal static decimal ToInteger(string s)
925  {
926  return decimal.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
927  }
928 
929  internal static Exception TryToInteger(string s, out decimal result)
930  {
931  if (!decimal.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result))
932  {
933  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Integer"));
934  }
935  return null;
936  }
937 
947  [CLSCompliant(false)]
948  [global::__DynamicallyInvokable]
949  public static sbyte ToSByte(string s)
950  {
951  return sbyte.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
952  }
953 
954  internal static Exception TryToSByte(string s, out sbyte result)
955  {
956  if (!sbyte.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result))
957  {
958  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "SByte"));
959  }
960  return null;
961  }
962 
972  [global::__DynamicallyInvokable]
973  public static short ToInt16(string s)
974  {
975  return short.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
976  }
977 
978  internal static Exception TryToInt16(string s, out short result)
979  {
980  if (!short.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result))
981  {
982  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Int16"));
983  }
984  return null;
985  }
986 
996  [global::__DynamicallyInvokable]
997  public static int ToInt32(string s)
998  {
999  return int.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
1000  }
1001 
1002  internal static Exception TryToInt32(string s, out int result)
1003  {
1004  if (!int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result))
1005  {
1006  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Int32"));
1007  }
1008  return null;
1009  }
1010 
1020  [global::__DynamicallyInvokable]
1021  public static long ToInt64(string s)
1022  {
1023  return long.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo);
1024  }
1025 
1026  internal static Exception TryToInt64(string s, out long result)
1027  {
1028  if (!long.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out result))
1029  {
1030  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Int64"));
1031  }
1032  return null;
1033  }
1034 
1044  [global::__DynamicallyInvokable]
1045  public static byte ToByte(string s)
1046  {
1047  return byte.Parse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
1048  }
1049 
1050  internal static Exception TryToByte(string s, out byte result)
1051  {
1052  if (!byte.TryParse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo, out result))
1053  {
1054  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Byte"));
1055  }
1056  return null;
1057  }
1058 
1068  [CLSCompliant(false)]
1069  [global::__DynamicallyInvokable]
1070  public static ushort ToUInt16(string s)
1071  {
1072  return ushort.Parse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
1073  }
1074 
1075  internal static Exception TryToUInt16(string s, out ushort result)
1076  {
1077  if (!ushort.TryParse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo, out result))
1078  {
1079  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "UInt16"));
1080  }
1081  return null;
1082  }
1083 
1093  [CLSCompliant(false)]
1094  [global::__DynamicallyInvokable]
1095  public static uint ToUInt32(string s)
1096  {
1097  return uint.Parse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
1098  }
1099 
1100  internal static Exception TryToUInt32(string s, out uint result)
1101  {
1102  if (!uint.TryParse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo, out result))
1103  {
1104  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "UInt32"));
1105  }
1106  return null;
1107  }
1108 
1118  [CLSCompliant(false)]
1119  [global::__DynamicallyInvokable]
1120  public static ulong ToUInt64(string s)
1121  {
1122  return ulong.Parse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo);
1123  }
1124 
1125  internal static Exception TryToUInt64(string s, out ulong result)
1126  {
1127  if (!ulong.TryParse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, NumberFormatInfo.InvariantInfo, out result))
1128  {
1129  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "UInt64"));
1130  }
1131  return null;
1132  }
1133 
1143  [global::__DynamicallyInvokable]
1144  public static float ToSingle(string s)
1145  {
1146  s = TrimString(s);
1147  if (s == "-INF")
1148  {
1149  return float.NegativeInfinity;
1150  }
1151  if (s == "INF")
1152  {
1153  return float.PositiveInfinity;
1154  }
1155  float num = float.Parse(s, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, NumberFormatInfo.InvariantInfo);
1156  if (num == 0f && s[0] == '-')
1157  {
1158  return -0f;
1159  }
1160  return num;
1161  }
1162 
1163  internal static Exception TryToSingle(string s, out float result)
1164  {
1165  s = TrimString(s);
1166  if (s == "-INF")
1167  {
1168  result = float.NegativeInfinity;
1169  return null;
1170  }
1171  if (s == "INF")
1172  {
1173  result = float.PositiveInfinity;
1174  return null;
1175  }
1176  if (!float.TryParse(s, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, NumberFormatInfo.InvariantInfo, out result))
1177  {
1178  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Single"));
1179  }
1180  if (result == 0f && s[0] == '-')
1181  {
1182  result = -0f;
1183  }
1184  return null;
1185  }
1186 
1196  [global::__DynamicallyInvokable]
1197  public static double ToDouble(string s)
1198  {
1199  s = TrimString(s);
1200  if (s == "-INF")
1201  {
1202  return double.NegativeInfinity;
1203  }
1204  if (s == "INF")
1205  {
1206  return double.PositiveInfinity;
1207  }
1208  double num = double.Parse(s, NumberStyles.Float, NumberFormatInfo.InvariantInfo);
1209  if (num == 0.0 && s[0] == '-')
1210  {
1211  return -0.0;
1212  }
1213  return num;
1214  }
1215 
1216  internal static Exception TryToDouble(string s, out double result)
1217  {
1218  s = TrimString(s);
1219  if (s == "-INF")
1220  {
1221  result = double.NegativeInfinity;
1222  return null;
1223  }
1224  if (s == "INF")
1225  {
1226  result = double.PositiveInfinity;
1227  return null;
1228  }
1229  if (!double.TryParse(s, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, NumberFormatInfo.InvariantInfo, out result))
1230  {
1231  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Double"));
1232  }
1233  if (result == 0.0 && s[0] == '-')
1234  {
1235  result = -0.0;
1236  }
1237  return null;
1238  }
1239 
1240  internal static double ToXPathDouble(object o)
1241  {
1242  string text = o as string;
1243  if (text != null)
1244  {
1245  text = TrimString(text);
1246  if (text.Length != 0 && text[0] != '+' && double.TryParse(text, NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, NumberFormatInfo.InvariantInfo, out double result))
1247  {
1248  return result;
1249  }
1250  return double.NaN;
1251  }
1252  if (o is double)
1253  {
1254  return (double)o;
1255  }
1256  if (o is bool)
1257  {
1258  if (!(bool)o)
1259  {
1260  return 0.0;
1261  }
1262  return 1.0;
1263  }
1264  try
1265  {
1266  return Convert.ToDouble(o, NumberFormatInfo.InvariantInfo);
1267  }
1268  catch (FormatException)
1269  {
1270  }
1271  catch (OverflowException)
1272  {
1273  }
1274  catch (ArgumentNullException)
1275  {
1276  }
1277  return double.NaN;
1278  }
1279 
1280  internal static string ToXPathString(object value)
1281  {
1282  string text = value as string;
1283  if (text != null)
1284  {
1285  return text;
1286  }
1287  if (value is double)
1288  {
1289  return ((double)value).ToString("R", NumberFormatInfo.InvariantInfo);
1290  }
1291  if (value is bool)
1292  {
1293  if (!(bool)value)
1294  {
1295  return "false";
1296  }
1297  return "true";
1298  }
1299  return Convert.ToString(value, NumberFormatInfo.InvariantInfo);
1300  }
1301 
1302  internal static double XPathRound(double value)
1303  {
1304  double num = Math.Round(value);
1305  if (value - num != 0.5)
1306  {
1307  return num;
1308  }
1309  return num + 1.0;
1310  }
1311 
1317  [global::__DynamicallyInvokable]
1318  public static TimeSpan ToTimeSpan(string s)
1319  {
1320  XsdDuration xsdDuration;
1321  try
1322  {
1323  xsdDuration = new XsdDuration(s);
1324  }
1325  catch (Exception)
1326  {
1327  throw new FormatException(Res.GetString("XmlConvert_BadFormat", s, "TimeSpan"));
1328  }
1329  return xsdDuration.ToTimeSpan();
1330  }
1331 
1332  internal static Exception TryToTimeSpan(string s, out TimeSpan result)
1333  {
1334  XsdDuration result2;
1335  Exception ex = XsdDuration.TryParse(s, out result2);
1336  if (ex != null)
1337  {
1338  result = TimeSpan.MinValue;
1339  return ex;
1340  }
1341  return result2.TryToTimeSpan(out result);
1342  }
1343 
1344  private static void CreateAllDateTimeFormats()
1345  {
1346  if (s_allDateTimeFormats == null)
1347  {
1348  s_allDateTimeFormats = new string[24]
1349  {
1350  "yyyy-MM-ddTHH:mm:ss.FFFFFFFzzzzzz",
1351  "yyyy-MM-ddTHH:mm:ss.FFFFFFF",
1352  "yyyy-MM-ddTHH:mm:ss.FFFFFFFZ",
1353  "HH:mm:ss.FFFFFFF",
1354  "HH:mm:ss.FFFFFFFZ",
1355  "HH:mm:ss.FFFFFFFzzzzzz",
1356  "yyyy-MM-dd",
1357  "yyyy-MM-ddZ",
1358  "yyyy-MM-ddzzzzzz",
1359  "yyyy-MM",
1360  "yyyy-MMZ",
1361  "yyyy-MMzzzzzz",
1362  "yyyy",
1363  "yyyyZ",
1364  "yyyyzzzzzz",
1365  "--MM-dd",
1366  "--MM-ddZ",
1367  "--MM-ddzzzzzz",
1368  "---dd",
1369  "---ddZ",
1370  "---ddzzzzzz",
1371  "--MM--",
1372  "--MM--Z",
1373  "--MM--zzzzzz"
1374  };
1375  }
1376  }
1377 
1385  [Obsolete("Use XmlConvert.ToDateTime() that takes in XmlDateTimeSerializationMode")]
1386  public static DateTime ToDateTime(string s)
1387  {
1388  return ToDateTime(s, AllDateTimeFormats);
1389  }
1390 
1400  public static DateTime ToDateTime(string s, string format)
1401  {
1402  return DateTime.ParseExact(s, format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite);
1403  }
1404 
1414  public static DateTime ToDateTime(string s, string[] formats)
1415  {
1416  return DateTime.ParseExact(s, formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite);
1417  }
1418 
1428  [global::__DynamicallyInvokable]
1429  public static DateTime ToDateTime(string s, XmlDateTimeSerializationMode dateTimeOption)
1430  {
1431  XsdDateTime xdt = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
1432  DateTime dateTime = xdt;
1433  switch (dateTimeOption)
1434  {
1435  case XmlDateTimeSerializationMode.Local:
1436  dateTime = SwitchToLocalTime(dateTime);
1437  break;
1439  dateTime = SwitchToUtcTime(dateTime);
1440  break;
1441  case XmlDateTimeSerializationMode.Unspecified:
1442  dateTime = new DateTime(dateTime.Ticks, DateTimeKind.Unspecified);
1443  break;
1444  default:
1445  throw new ArgumentException(Res.GetString("Sch_InvalidDateTimeOption", dateTimeOption, "dateTimeOption"));
1446  case XmlDateTimeSerializationMode.RoundtripKind:
1447  break;
1448  }
1449  return dateTime;
1450  }
1451 
1460  [global::__DynamicallyInvokable]
1461  public static DateTimeOffset ToDateTimeOffset(string s)
1462  {
1463  if (s == null)
1464  {
1465  throw new ArgumentNullException("s");
1466  }
1467  XsdDateTime xdt = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
1468  return xdt;
1469  }
1470 
1479  [global::__DynamicallyInvokable]
1480  public static DateTimeOffset ToDateTimeOffset(string s, string format)
1481  {
1482  if (s == null)
1483  {
1484  throw new ArgumentNullException("s");
1485  }
1486  return DateTimeOffset.ParseExact(s, format, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite);
1487  }
1488 
1493  [global::__DynamicallyInvokable]
1494  public static DateTimeOffset ToDateTimeOffset(string s, string[] formats)
1495  {
1496  if (s == null)
1497  {
1498  throw new ArgumentNullException("s");
1499  }
1500  return DateTimeOffset.ParseExact(s, formats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite);
1501  }
1502 
1506  [global::__DynamicallyInvokable]
1507  public static Guid ToGuid(string s)
1508  {
1509  return new Guid(s);
1510  }
1511 
1512  internal static Exception TryToGuid(string s, out Guid result)
1513  {
1514  Exception result2 = null;
1515  result = Guid.Empty;
1516  try
1517  {
1518  result = new Guid(s);
1519  return result2;
1520  }
1521  catch (ArgumentException)
1522  {
1523  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Guid"));
1524  }
1525  catch (FormatException)
1526  {
1527  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Guid"));
1528  }
1529  }
1530 
1531  private static DateTime SwitchToLocalTime(DateTime value)
1532  {
1533  switch (value.Kind)
1534  {
1535  case DateTimeKind.Local:
1536  return value;
1537  case DateTimeKind.Unspecified:
1538  return new DateTime(value.Ticks, DateTimeKind.Local);
1539  case DateTimeKind.Utc:
1540  return value.ToLocalTime();
1541  default:
1542  return value;
1543  }
1544  }
1545 
1546  private static DateTime SwitchToUtcTime(DateTime value)
1547  {
1548  switch (value.Kind)
1549  {
1550  case DateTimeKind.Utc:
1551  return value;
1552  case DateTimeKind.Unspecified:
1553  return new DateTime(value.Ticks, DateTimeKind.Utc);
1554  case DateTimeKind.Local:
1555  return value.ToUniversalTime();
1556  default:
1557  return value;
1558  }
1559  }
1560 
1561  internal static Uri ToUri(string s)
1562  {
1563  if (s != null && s.Length > 0)
1564  {
1565  s = TrimString(s);
1566  if (s.Length == 0 || s.IndexOf("##", StringComparison.Ordinal) != -1)
1567  {
1568  throw new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Uri"));
1569  }
1570  }
1571  if (!Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out Uri result))
1572  {
1573  throw new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Uri"));
1574  }
1575  return result;
1576  }
1577 
1578  internal static Exception TryToUri(string s, out Uri result)
1579  {
1580  result = null;
1581  if (s != null && s.Length > 0)
1582  {
1583  s = TrimString(s);
1584  if (s.Length == 0 || s.IndexOf("##", StringComparison.Ordinal) != -1)
1585  {
1586  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Uri"));
1587  }
1588  }
1589  if (!Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out result))
1590  {
1591  return new FormatException(Res.GetString("XmlConvert_BadFormat", s, "Uri"));
1592  }
1593  return null;
1594  }
1595 
1596  internal static bool StrEqual(char[] chars, int strPos1, int strLen1, string str2)
1597  {
1598  if (strLen1 != str2.Length)
1599  {
1600  return false;
1601  }
1602  int i;
1603  for (i = 0; i < strLen1 && chars[strPos1 + i] == str2[i]; i++)
1604  {
1605  }
1606  return i == strLen1;
1607  }
1608 
1609  internal static string TrimString(string value)
1610  {
1611  return value.Trim(WhitespaceChars);
1612  }
1613 
1614  internal static string TrimStringStart(string value)
1615  {
1616  return value.TrimStart(WhitespaceChars);
1617  }
1618 
1619  internal static string TrimStringEnd(string value)
1620  {
1621  return value.TrimEnd(WhitespaceChars);
1622  }
1623 
1624  internal static string[] SplitString(string value)
1625  {
1626  return value.Split(WhitespaceChars, StringSplitOptions.RemoveEmptyEntries);
1627  }
1628 
1629  internal static string[] SplitString(string value, StringSplitOptions splitStringOptions)
1630  {
1631  return value.Split(WhitespaceChars, splitStringOptions);
1632  }
1633 
1634  internal static bool IsNegativeZero(double value)
1635  {
1636  if (value == 0.0 && DoubleToInt64Bits(value) == DoubleToInt64Bits(-0.0))
1637  {
1638  return true;
1639  }
1640  return false;
1641  }
1642 
1643  private unsafe static long DoubleToInt64Bits(double value)
1644  {
1645  return *(long*)(&value);
1646  }
1647 
1648  internal static void VerifyCharData(string data, ExceptionType exceptionType)
1649  {
1650  VerifyCharData(data, exceptionType, exceptionType);
1651  }
1652 
1653  internal unsafe static void VerifyCharData(string data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType)
1654  {
1655  if (data == null || data.Length == 0)
1656  {
1657  return;
1658  }
1659  int num = 0;
1660  int length = data.Length;
1661  while (true)
1662  {
1663  if (num < length && (xmlCharType.charProperties[(int)data[num]] & 0x10) != 0)
1664  {
1665  num++;
1666  continue;
1667  }
1668  if (num == length)
1669  {
1670  return;
1671  }
1672  char ch = data[num];
1673  if (!XmlCharType.IsHighSurrogate(ch))
1674  {
1675  break;
1676  }
1677  if (num + 1 == length)
1678  {
1679  throw CreateException("Xml_InvalidSurrogateMissingLowChar", invSurrogateExceptionType, 0, num + 1);
1680  }
1681  ch = data[num + 1];
1682  if (XmlCharType.IsLowSurrogate(ch))
1683  {
1684  num += 2;
1685  continue;
1686  }
1687  throw CreateInvalidSurrogatePairException(data[num + 1], data[num], invSurrogateExceptionType, 0, num + 1);
1688  }
1689  throw CreateInvalidCharException(data, num, invCharExceptionType);
1690  }
1691 
1692  internal unsafe static void VerifyCharData(char[] data, int offset, int len, ExceptionType exceptionType)
1693  {
1694  if (data == null || len == 0)
1695  {
1696  return;
1697  }
1698  int num = offset;
1699  int num2 = offset + len;
1700  while (true)
1701  {
1702  if (num < num2 && (xmlCharType.charProperties[(int)data[num]] & 0x10) != 0)
1703  {
1704  num++;
1705  continue;
1706  }
1707  if (num == num2)
1708  {
1709  return;
1710  }
1711  char ch = data[num];
1712  if (!XmlCharType.IsHighSurrogate(ch))
1713  {
1714  break;
1715  }
1716  if (num + 1 == num2)
1717  {
1718  throw CreateException("Xml_InvalidSurrogateMissingLowChar", exceptionType, 0, offset - num + 1);
1719  }
1720  ch = data[num + 1];
1721  if (XmlCharType.IsLowSurrogate(ch))
1722  {
1723  num += 2;
1724  continue;
1725  }
1726  throw CreateInvalidSurrogatePairException(data[num + 1], data[num], exceptionType, 0, offset - num + 1);
1727  }
1728  throw CreateInvalidCharException(data, len, num, exceptionType);
1729  }
1730 
1731  internal static string EscapeValueForDebuggerDisplay(string value)
1732  {
1733  StringBuilder stringBuilder = null;
1734  int i = 0;
1735  int num = 0;
1736  for (; i < value.Length; i++)
1737  {
1738  char c = value[i];
1739  if (c < ' ' || c == '"')
1740  {
1741  if (stringBuilder == null)
1742  {
1743  stringBuilder = new StringBuilder(value.Length + 4);
1744  }
1745  if (i - num > 0)
1746  {
1747  stringBuilder.Append(value, num, i - num);
1748  }
1749  num = i + 1;
1750  switch (c)
1751  {
1752  case '"':
1753  stringBuilder.Append("\\\"");
1754  break;
1755  case '\r':
1756  stringBuilder.Append("\\r");
1757  break;
1758  case '\n':
1759  stringBuilder.Append("\\n");
1760  break;
1761  case '\t':
1762  stringBuilder.Append("\\t");
1763  break;
1764  default:
1765  stringBuilder.Append(c);
1766  break;
1767  }
1768  }
1769  }
1770  if (stringBuilder == null)
1771  {
1772  return value;
1773  }
1774  if (i - num > 0)
1775  {
1776  stringBuilder.Append(value, num, i - num);
1777  }
1778  return stringBuilder.ToString();
1779  }
1780 
1781  internal static Exception CreateException(string res, ExceptionType exceptionType)
1782  {
1783  return CreateException(res, exceptionType, 0, 0);
1784  }
1785 
1786  internal static Exception CreateException(string res, ExceptionType exceptionType, int lineNo, int linePos)
1787  {
1788  switch (exceptionType)
1789  {
1790  case ExceptionType.ArgumentException:
1791  return new ArgumentException(Res.GetString(res));
1792  default:
1793  return new XmlException(res, string.Empty, lineNo, linePos);
1794  }
1795  }
1796 
1797  internal static Exception CreateException(string res, string arg, ExceptionType exceptionType)
1798  {
1799  return CreateException(res, arg, exceptionType, 0, 0);
1800  }
1801 
1802  internal static Exception CreateException(string res, string arg, ExceptionType exceptionType, int lineNo, int linePos)
1803  {
1804  switch (exceptionType)
1805  {
1806  case ExceptionType.ArgumentException:
1807  return new ArgumentException(Res.GetString(res, arg));
1808  default:
1809  return new XmlException(res, arg, lineNo, linePos);
1810  }
1811  }
1812 
1813  internal static Exception CreateException(string res, string[] args, ExceptionType exceptionType)
1814  {
1815  return CreateException(res, args, exceptionType, 0, 0);
1816  }
1817 
1818  internal static Exception CreateException(string res, string[] args, ExceptionType exceptionType, int lineNo, int linePos)
1819  {
1820  switch (exceptionType)
1821  {
1822  case ExceptionType.ArgumentException:
1823  return new ArgumentException(Res.GetString(res, args));
1824  default:
1825  return new XmlException(res, args, lineNo, linePos);
1826  }
1827  }
1828 
1829  internal static Exception CreateInvalidSurrogatePairException(char low, char hi)
1830  {
1831  return CreateInvalidSurrogatePairException(low, hi, ExceptionType.ArgumentException);
1832  }
1833 
1834  internal static Exception CreateInvalidSurrogatePairException(char low, char hi, ExceptionType exceptionType)
1835  {
1836  return CreateInvalidSurrogatePairException(low, hi, exceptionType, 0, 0);
1837  }
1838 
1839  internal static Exception CreateInvalidSurrogatePairException(char low, char hi, ExceptionType exceptionType, int lineNo, int linePos)
1840  {
1841  string[] obj = new string[2];
1842  uint num = hi;
1843  obj[0] = num.ToString("X", CultureInfo.InvariantCulture);
1844  num = low;
1845  obj[1] = num.ToString("X", CultureInfo.InvariantCulture);
1846  string[] args = obj;
1847  return CreateException("Xml_InvalidSurrogatePairWithArgs", args, exceptionType, lineNo, linePos);
1848  }
1849 
1850  internal static Exception CreateInvalidHighSurrogateCharException(char hi)
1851  {
1852  return CreateInvalidHighSurrogateCharException(hi, ExceptionType.ArgumentException);
1853  }
1854 
1855  internal static Exception CreateInvalidHighSurrogateCharException(char hi, ExceptionType exceptionType)
1856  {
1857  return CreateInvalidHighSurrogateCharException(hi, exceptionType, 0, 0);
1858  }
1859 
1860  internal static Exception CreateInvalidHighSurrogateCharException(char hi, ExceptionType exceptionType, int lineNo, int linePos)
1861  {
1862  uint num = hi;
1863  return CreateException("Xml_InvalidSurrogateHighChar", num.ToString("X", CultureInfo.InvariantCulture), exceptionType, lineNo, linePos);
1864  }
1865 
1866  internal static Exception CreateInvalidCharException(char[] data, int length, int invCharPos)
1867  {
1868  return CreateInvalidCharException(data, length, invCharPos, ExceptionType.ArgumentException);
1869  }
1870 
1871  internal static Exception CreateInvalidCharException(char[] data, int length, int invCharPos, ExceptionType exceptionType)
1872  {
1873  return CreateException("Xml_InvalidCharacter", XmlException.BuildCharExceptionArgs(data, length, invCharPos), exceptionType, 0, invCharPos + 1);
1874  }
1875 
1876  internal static Exception CreateInvalidCharException(string data, int invCharPos)
1877  {
1878  return CreateInvalidCharException(data, invCharPos, ExceptionType.ArgumentException);
1879  }
1880 
1881  internal static Exception CreateInvalidCharException(string data, int invCharPos, ExceptionType exceptionType)
1882  {
1883  return CreateException("Xml_InvalidCharacter", XmlException.BuildCharExceptionArgs(data, invCharPos), exceptionType, 0, invCharPos + 1);
1884  }
1885 
1886  internal static Exception CreateInvalidCharException(char invChar, char nextChar)
1887  {
1888  return CreateInvalidCharException(invChar, nextChar, ExceptionType.ArgumentException);
1889  }
1890 
1891  internal static Exception CreateInvalidCharException(char invChar, char nextChar, ExceptionType exceptionType)
1892  {
1893  return CreateException("Xml_InvalidCharacter", XmlException.BuildCharExceptionArgs(invChar, nextChar), exceptionType);
1894  }
1895 
1896  internal static Exception CreateInvalidNameCharException(string name, int index, ExceptionType exceptionType)
1897  {
1898  return CreateException((index == 0) ? "Xml_BadStartNameChar" : "Xml_BadNameChar", XmlException.BuildCharExceptionArgs(name, index), exceptionType, 0, index + 1);
1899  }
1900 
1901  internal static ArgumentException CreateInvalidNameArgumentException(string name, string argumentName)
1902  {
1903  if (name != null)
1904  {
1905  return new ArgumentException(Res.GetString("Xml_EmptyName"), argumentName);
1906  }
1907  return new ArgumentNullException(argumentName);
1908  }
1909  }
1910 }
UriKind
Defines the kinds of T:System.Uris for the M:System.Uri.IsWellFormedUriString(System....
Definition: UriKind.cs:5
static string ToString(DateTimeOffset value)
Converts the supplied T:System.DateTimeOffset to a T:System.String.
Definition: XmlConvert.cs:805
override string ToString()
Creates and returns a string representation of the current exception.
Definition: Exception.cs:474
static string ToString(double value)
Converts the T:System.Double to a T:System.String.
Definition: XmlConvert.cs:729
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
static DateTime ToDateTime(string s)
Converts the T:System.String to a T:System.DateTime equivalent.
Definition: XmlConvert.cs:1386
static unsafe bool IsXmlChar(char ch)
Checks if the passed-in character is a valid XML character.
Definition: XmlConvert.cs:560
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static float ToSingle(string s)
Converts the T:System.String to a T:System.Single equivalent.
Definition: XmlConvert.cs:1144
static DateTime ParseExact(string s, string format, IFormatProvider provider)
Converts the specified string representation of a date and time to its T:System.DateTime equivalent u...
Definition: DateTime.cs:1325
static string ToString(ushort value)
Converts the T:System.UInt16 to a T:System.String.
Definition: XmlConvert.cs:679
bool MoveNext()
Advances the enumerator to the next element of the collection.
Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Un...
static DateTimeOffset ToDateTimeOffset(string s, string format)
Converts the supplied T:System.String to a T:System.DateTimeOffset equivalent.
Definition: XmlConvert.cs:1480
static char ToChar(string s)
Converts the T:System.String to a T:System.Char equivalent.
Definition: XmlConvert.cs:878
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static DateTimeOffset ToDateTimeOffset(string s, string[] formats)
Converts the supplied T:System.String to a T:System.DateTimeOffset equivalent.
Definition: XmlConvert.cs:1494
static string VerifyWhitespace(string content)
Returns the passed-in string instance if all the characters in the string argument are valid whitespa...
Definition: XmlConvert.cs:525
static bool IsPublicIdChar(char ch)
Returns the passed-in character instance if the character in the argument is a valid public id charac...
Definition: XmlConvert.cs:583
static string VerifyPublicId(string publicId)
Returns the passed in string instance if all the characters in the string argument are valid public i...
Definition: XmlConvert.cs:506
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
static string VerifyXmlChars(string content)
Returns the passed-in string if all the characters and surrogate pair characters in the string argume...
Definition: XmlConvert.cs:491
static long ToInt64(string s)
Converts the T:System.String to a T:System.Int64 equivalent.
Definition: XmlConvert.cs:1021
Definition: __Canon.cs:3
static string EncodeName(string name)
Converts the name to a valid XML name.
Definition: XmlConvert.cs:54
static string ToString(bool value)
Converts the T:System.Boolean to a T:System.String.
Definition: XmlConvert.cs:601
static string EncodeLocalName(string name)
Converts the name to a valid XML local name.
Definition: XmlConvert.cs:72
static string DecodeName(string name)
Decodes a name. This method does the reverse of the M:System.Xml.XmlConvert.EncodeName(System....
Definition: XmlConvert.cs:81
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
Provides culture-specific information about the format of date and time values.
static string ToString(DateTimeOffset value, string format)
Converts the supplied T:System.DateTimeOffset to a T:System.String in the specified format.
Definition: XmlConvert.cs:815
static string ToString(DateTime value, string format)
Converts the T:System.DateTime to a T:System.String.
Definition: XmlConvert.cs:768
A type representing a date and time value.
static DateTime ToDateTime(string s, string format)
Converts the T:System.String to a T:System.DateTime equivalent.
Definition: XmlConvert.cs:1400
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
Definition: NumberStyles.cs:10
static string EncodeNmToken(string name)
Verifies the name is valid according to the XML specification.
Definition: XmlConvert.cs:63
static string ToString(float value)
Converts the T:System.Single to a T:System.String.
Definition: XmlConvert.cs:708
static Guid ToGuid(string s)
Converts the T:System.String to a T:System.Guid equivalent.
Definition: XmlConvert.cs:1507
static byte ToByte(string s)
Converts the T:System.String to a T:System.Byte equivalent.
Definition: XmlConvert.cs:1045
static string VerifyName(string name)
Verifies that the name is a valid name according to the W3C Extended Markup Language recommendation.
Definition: XmlConvert.cs:301
static string ToString(decimal value)
Converts the T:System.Decimal to a T:System.String.
Definition: XmlConvert.cs:623
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
static string ToString(sbyte value)
Converts the T:System.SByte to a T:System.String.
Definition: XmlConvert.cs:633
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
static uint ToUInt32(string s)
Converts the T:System.String to a T:System.UInt32 equivalent.
Definition: XmlConvert.cs:1095
A cast or conversion operation, such as (SampleType)obj in C::or CType(obj, SampleType) in Visual Bas...
The exception that is thrown when the format of an argument is invalid, or when a composite format st...
static string ToString(ulong value)
Converts the T:System.UInt64 to a T:System.String.
Definition: XmlConvert.cs:699
StringSplitOptions
Specifies whether applicable Overload:System.String.Split method overloads include or omit empty subs...
IEnumerator GetEnumerator()
Provides an enumerator that iterates through the collection.
int Index
The position in the original string where the first character of the captured substring is found.
Definition: Capture.cs:18
static string ToString(byte value)
Converts the T:System.Byte to a T:System.String.
Definition: XmlConvert.cs:669
static string ToString(DateTime value)
Converts the T:System.DateTime to a T:System.String.
Definition: XmlConvert.cs:759
static string ToString(int value)
Converts the T:System.Int32 to a T:System.String.
Definition: XmlConvert.cs:651
static string ToString(Guid value)
Converts the T:System.Guid to a T:System.String.
Definition: XmlConvert.cs:824
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider)
Converts the specified string representation of a date and time to its T:System.DateTimeOffset equiva...
static unsafe bool IsNCNameChar(char ch)
Checks whether the passed-in character is a valid non-colon character type.
Definition: XmlConvert.cs:551
static string VerifyTOKEN(string token)
Verifies that the string is a valid token according to the W3C XML Schema Part2: Datatypes recommenda...
Definition: XmlConvert.cs:398
static unsafe bool IsStartNCNameChar(char ch)
Checks if the passed-in character is a valid Start Name Character type.
Definition: XmlConvert.cs:543
static DateTime ToDateTime(string s, XmlDateTimeSerializationMode dateTimeOption)
Converts the T:System.String to a T:System.DateTime using the T:System.Xml.XmlDateTimeSerializationMo...
Definition: XmlConvert.cs:1429
static string VerifyNMTOKEN(string name)
Verifies that the string is a valid NMTOKEN according to the W3C XML Schema Part2: Datatypes recommen...
Definition: XmlConvert.cs:431
static TimeSpan ToTimeSpan(string s)
Converts the T:System.String to a T:System.TimeSpan equivalent.
Definition: XmlConvert.cs:1318
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
Returns detailed information about the last exception.
Definition: XmlException.cs:12
Represents the results from a single regular expression match.
Definition: Match.cs:8
The exception that is thrown when one of the arguments provided to a method is not valid.
static string ToString(short value)
Converts the T:System.Int16 to a T:System.String.
Definition: XmlConvert.cs:642
static string VerifyNCName(string name)
Verifies that the name is a valid NCName according to the W3C Extended Markup Language recommendation...
Definition: XmlConvert.cs:361
static ulong ToUInt64(string s)
Converts the T:System.String to a T:System.UInt64 equivalent.
Definition: XmlConvert.cs:1120
static DateTime ToDateTime(string s, string[] formats)
Converts the T:System.String to a T:System.DateTime equivalent.
Definition: XmlConvert.cs:1414
static ushort ToUInt16(string s)
Converts the T:System.String to a T:System.UInt16 equivalent.
Definition: XmlConvert.cs:1070
static readonly TimeSpan MinValue
Represents the minimum T:System.TimeSpan value. This field is read-only.
Definition: TimeSpan.cs:72
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
static unsafe bool IsWhitespaceChar(char ch)
Checks if the passed-in character is a valid XML whitespace character.
Definition: XmlConvert.cs:592
DateTimeKind
Specifies whether a T:System.DateTime object represents a local time, a Coordinated Universal Time (U...
Definition: DateTimeKind.cs:9
static bool ToBoolean(string s)
Converts the T:System.String to a T:System.Boolean equivalent.
Definition: XmlConvert.cs:837
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
static string ToString(DateTime value, XmlDateTimeSerializationMode dateTimeOption)
Converts the T:System.DateTime to a T:System.String using the T:System.Xml.XmlDateTimeSerializationMo...
Definition: XmlConvert.cs:780
static short ToInt16(string s)
Converts the T:System.String to a T:System.Int16 equivalent.
Definition: XmlConvert.cs:973
static string ToString(long value)
Converts the T:System.Int64 to a T:System.String.
Definition: XmlConvert.cs:660
static string ToString(char value)
Converts the T:System.Char to a T:System.String.
Definition: XmlConvert.cs:614
static decimal ToDecimal(string s)
Converts the T:System.String to a T:System.Decimal equivalent.
Definition: XmlConvert.cs:910
static MatchCollection Matches(string input, string pattern)
Searches the specified input string for all occurrences of a specified regular expression.
Definition: Regex.cs:744
static string ToString(TimeSpan value)
Converts the T:System.TimeSpan to a T:System.String.
Definition: XmlConvert.cs:750
static readonly Guid Empty
A read-only instance of the T:System.Guid structure whose value is all zeros.
Definition: Guid.cs:126
static DateTimeFormatInfo InvariantInfo
Gets the default read-only T:System.Globalization.DateTimeFormatInfo object that is culture-independe...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
Returns detailed information about the schema exception.
static bool IsXmlSurrogatePair(char lowChar, char highChar)
Checks if the passed-in surrogate pair of characters is a valid XML character.
Definition: XmlConvert.cs:570
static DateTimeOffset ToDateTimeOffset(string s)
Converts the supplied T:System.String to a T:System.DateTimeOffset equivalent.
Definition: XmlConvert.cs:1461
static sbyte ToSByte(string s)
Converts the T:System.String to a T:System.SByte equivalent.
Definition: XmlConvert.cs:949
static string ToString(uint value)
Converts the T:System.UInt32 to a T:System.String.
Definition: XmlConvert.cs:689
static int ToInt32(string s)
Converts the T:System.String to a T:System.Int32 equivalent.
Definition: XmlConvert.cs:997
DateTimeStyles
Defines the formatting options that customize string parsing for some date and time parsing methods.
Represents an immutable regular expression.To browse the .NET Framework source code for this type,...
Definition: Regex.cs:16
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
XmlDateTimeSerializationMode
Specifies how to treat the time value when converting between string and T:System....
static NumberFormatInfo InvariantInfo
Gets a read-only T:System.Globalization.NumberFormatInfo object that is culture-independent (invarian...
long Ticks
Gets the number of ticks that represent the date and time of this instance.
Definition: DateTime.cs:315
Encodes and decodes XML names, and provides methods for converting between common language runtime ty...
Definition: XmlConvert.cs:11
Represents the set of successful matches found by iteratively applying a regular expression pattern t...
Provides culture-specific information for formatting and parsing numeric values.
static double ToDouble(string s)
Converts the T:System.String to a T:System.Double equivalent.
Definition: XmlConvert.cs:1197