2010-05-27 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Runtime.Serialization / System.Xml / XmlDictionaryReaderQuotas.cs
blob0b9cda9df370a7377b4b34552301bb78e505d928
1 //
2 // XmlDictionaryReaderQuotas.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #if NET_2_0
29 namespace System.Xml
31 public sealed class XmlDictionaryReaderQuotas
33 static XmlDictionaryReaderQuotas max;
35 static XmlDictionaryReaderQuotas ()
37 max = new XmlDictionaryReaderQuotas (true);
40 readonly bool is_readonly;
41 int array_len, bytes, depth, nt_chars, text_len;
43 public XmlDictionaryReaderQuotas ()
44 : this (false)
48 private XmlDictionaryReaderQuotas (bool max)
50 is_readonly = max;
51 array_len = max ? int.MaxValue : 0x4000;
52 bytes = max ? int.MaxValue : 0x1000;
53 depth = max ? int.MaxValue : 0x20;
54 nt_chars = max ? int.MaxValue : 0x4000;
55 text_len = max ? int.MaxValue : 0x2000;
58 public static XmlDictionaryReaderQuotas Max {
59 get { return max; }
62 public int MaxArrayLength {
63 get { return array_len; }
64 set { array_len = Check (value); }
67 public int MaxBytesPerRead {
68 get { return bytes; }
69 set { bytes = Check (value); }
72 public int MaxDepth {
73 get { return depth; }
74 set { depth = Check (value); }
77 public int MaxNameTableCharCount {
78 get { return nt_chars; }
79 set { nt_chars = Check (value); }
82 public int MaxStringContentLength {
83 get { return text_len; }
84 set { text_len = Check (value); }
87 private int Check (int value)
89 if (is_readonly)
90 throw new InvalidOperationException ("This quota is read-only.");
91 if (value <= 0)
92 throw new ArgumentException ("Value must be positive integer.");
93 return value;
96 public void CopyTo (XmlDictionaryReaderQuotas quota)
98 quota.array_len = array_len;
99 quota.bytes = bytes;
100 quota.depth = depth;
101 quota.nt_chars = nt_chars;
102 quota.text_len = text_len;
106 #endif