2
0

XmlDictionaryReaderQuotas.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #if NET_2_0
  2. namespace System.Xml
  3. {
  4. public class XmlDictionaryReaderQuotas
  5. {
  6. static XmlDictionaryReaderQuotas std, max;
  7. static XmlDictionaryReaderQuotas ()
  8. {
  9. std = new XmlDictionaryReaderQuotas ();
  10. max = new XmlDictionaryReaderQuotas ();
  11. }
  12. readonly bool is_readonly;
  13. int array_len, bytes, depth, nt_chars, text_len;
  14. public XmlDictionaryReaderQuotas ()
  15. : this (false)
  16. {
  17. }
  18. private XmlDictionaryReaderQuotas (bool isReadOnly)
  19. {
  20. is_readonly = isReadOnly;
  21. array_len = DefaultMaxArrayLength;
  22. bytes = DefaultMaxBytesPerRead;
  23. depth = DefaultMaxDepth;
  24. nt_chars = DefaultMaxNameTableCharCount;
  25. text_len = DefaultMaxStringContentLength;
  26. }
  27. public const int DefaultMaxArrayLength = int.MaxValue;
  28. public const int DefaultMaxBytesPerRead = int.MaxValue;
  29. public const int DefaultMaxDepth = int.MaxValue;
  30. public const int DefaultMaxNameTableCharCount = int.MaxValue;
  31. public const int DefaultMaxStringContentLength = int.MaxValue;
  32. public static XmlDictionaryReaderQuotas Default {
  33. get { return std; }
  34. }
  35. public static XmlDictionaryReaderQuotas Max {
  36. get { return max; }
  37. }
  38. public int MaxArrayLength {
  39. get { return array_len; }
  40. set { array_len = Check (value); }
  41. }
  42. public int MaxBytesPerRead {
  43. get { return bytes; }
  44. set { bytes = Check (value); }
  45. }
  46. public int MaxDepth {
  47. get { return depth; }
  48. set { depth = Check (value); }
  49. }
  50. public int MaxNameTableCharCount {
  51. get { return nt_chars; }
  52. set { nt_chars = Check (value); }
  53. }
  54. public int MaxStringContentLength {
  55. get { return text_len; }
  56. set { text_len = Check (value); }
  57. }
  58. private int Check (int value)
  59. {
  60. if (is_readonly)
  61. throw new InvalidOperationException ("This quota is read-only.");
  62. if (value <= 0)
  63. throw new ArgumentException ("Value must be positive integer.");
  64. return value;
  65. }
  66. public void CopyTo (XmlDictionaryReaderQuotas quota)
  67. {
  68. quota.array_len = array_len;
  69. quota.bytes = bytes;
  70. quota.depth = depth;
  71. quota.nt_chars = nt_chars;
  72. quota.text_len = text_len;
  73. }
  74. }
  75. }
  76. #endif