1 //-----------------------------------------------------------------------
2 // <copyright file="WrappedXmlDictionaryReader.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //-----------------------------------------------------------------------
6 
7 namespace System.IdentityModel
8 {
9     using System.Xml;
10 
11     /// <summary>
12     /// This class wraps a given _reader and delegates all calls to it.
13     /// XmlDictionaryReader class does not provide a way to set the _reader
14     /// Quotas on the XmlDictionaryReader.CreateDictionaryReader(XmlReader)
15     /// API. This class overrides XmlDictionaryReader.Quotas property and
16     /// hence custom quotas can be specified.
17     /// </summary>
18     internal class WrappedXmlDictionaryReader : XmlDictionaryReader, IXmlLineInfo
19     {
20         private XmlReader reader;
21         private XmlDictionaryReaderQuotas xmlDictionaryReaderQuotas;
22 
WrappedXmlDictionaryReader( XmlReader reader, XmlDictionaryReaderQuotas xmlDictionaryReaderQuotas)23         public WrappedXmlDictionaryReader(
24             XmlReader reader,
25             XmlDictionaryReaderQuotas xmlDictionaryReaderQuotas)
26         {
27             if (reader == null)
28             {
29                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
30             }
31 
32             if (xmlDictionaryReaderQuotas == null)
33             {
34                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlDictionaryReaderQuotas");
35             }
36 
37             this.reader = reader;
38             this.xmlDictionaryReaderQuotas = xmlDictionaryReaderQuotas;
39         }
40 
41         public override int AttributeCount
42         {
43             get
44             {
45                 return this.reader.AttributeCount;
46             }
47         }
48 
49         public override string BaseURI
50         {
51             get
52             {
53                 return this.reader.BaseURI;
54             }
55         }
56 
57         public override bool CanReadBinaryContent
58         {
59             get { return this.reader.CanReadBinaryContent; }
60         }
61 
62         public override bool CanReadValueChunk
63         {
64             get { return this.reader.CanReadValueChunk; }
65         }
66 
67         public override int Depth
68         {
69             get
70             {
71                 return this.reader.Depth;
72             }
73         }
74 
75         public override bool EOF
76         {
77             get
78             {
79                 return this.reader.EOF;
80             }
81         }
82 
83         public override bool HasValue
84         {
85             get
86             {
87                 return this.reader.HasValue;
88             }
89         }
90 
91         public override bool IsDefault
92         {
93             get
94             {
95                 return this.reader.IsDefault;
96             }
97         }
98 
99         public override bool IsEmptyElement
100         {
101             get
102             {
103                 return this.reader.IsEmptyElement;
104             }
105         }
106 
107         public override string LocalName
108         {
109             get
110             {
111                 return this.reader.LocalName;
112             }
113         }
114 
115         public override string Name
116         {
117             get
118             {
119                 return this.reader.Name;
120             }
121         }
122 
123         public override string NamespaceURI
124         {
125             get
126             {
127                 return this.reader.NamespaceURI;
128             }
129         }
130 
131         public override XmlNameTable NameTable
132         {
133             get
134             {
135                 return this.reader.NameTable;
136             }
137         }
138 
139         public override XmlNodeType NodeType
140         {
141             get
142             {
143                 return this.reader.NodeType;
144             }
145         }
146 
147         public override string Prefix
148         {
149             get
150             {
151                 return this.reader.Prefix;
152             }
153         }
154 
155         public override char QuoteChar
156         {
157             get
158             {
159                 return this.reader.QuoteChar;
160             }
161         }
162 
163         public override ReadState ReadState
164         {
165             get
166             {
167                 return this.reader.ReadState;
168             }
169         }
170 
171         public override string Value
172         {
173             get
174             {
175                 return this.reader.Value;
176             }
177         }
178 
179         public override string XmlLang
180         {
181             get
182             {
183                 return this.reader.XmlLang;
184             }
185         }
186 
187         public override XmlSpace XmlSpace
188         {
189             get
190             {
191                 return this.reader.XmlSpace;
192             }
193         }
194 
195         public override Type ValueType
196         {
197             get
198             {
199                 return this.reader.ValueType;
200             }
201         }
202 
203         public int LineNumber
204         {
205             get
206             {
207                 IXmlLineInfo lineInfo = this.reader as IXmlLineInfo;
208 
209                 if (lineInfo == null)
210                 {
211                     return 1;
212                 }
213 
214                 return lineInfo.LineNumber;
215             }
216         }
217 
218         public int LinePosition
219         {
220             get
221             {
222                 IXmlLineInfo lineInfo = this.reader as IXmlLineInfo;
223 
224                 if (lineInfo == null)
225                 {
226                     return 1;
227                 }
228 
229                 return lineInfo.LinePosition;
230             }
231         }
232 
233         public override XmlDictionaryReaderQuotas Quotas
234         {
235             get
236             {
237                 return this.xmlDictionaryReaderQuotas;
238             }
239         }
240 
241         public override string this[int index]
242         {
243             get
244             {
245                 return this.reader[index];
246             }
247         }
248 
249         public override string this[string name]
250         {
251             get
252             {
253                 return this.reader[name];
254             }
255         }
256 
257         public override string this[string name, string namespaceUri]
258         {
259             get
260             {
261                 return this.reader[name, namespaceUri];
262             }
263         }
264 
Close()265         public override void Close()
266         {
267             this.reader.Close();
268         }
269 
GetAttribute(int index)270         public override string GetAttribute(int index)
271         {
272             return this.reader.GetAttribute(index);
273         }
274 
GetAttribute(string name)275         public override string GetAttribute(string name)
276         {
277             return this.reader.GetAttribute(name);
278         }
279 
GetAttribute(string name, string namespaceUri)280         public override string GetAttribute(string name, string namespaceUri)
281         {
282             return this.reader.GetAttribute(name, namespaceUri);
283         }
284 
IsStartElement(string name)285         public override bool IsStartElement(string name)
286         {
287             return this.reader.IsStartElement(name);
288         }
289 
IsStartElement(string localName, string namespaceUri)290         public override bool IsStartElement(string localName, string namespaceUri)
291         {
292             return this.reader.IsStartElement(localName, namespaceUri);
293         }
294 
LookupNamespace(string namespaceUri)295         public override string LookupNamespace(string namespaceUri)
296         {
297             return this.reader.LookupNamespace(namespaceUri);
298         }
299 
MoveToAttribute(int index)300         public override void MoveToAttribute(int index)
301         {
302             this.reader.MoveToAttribute(index);
303         }
304 
MoveToAttribute(string name)305         public override bool MoveToAttribute(string name)
306         {
307             return this.reader.MoveToAttribute(name);
308         }
309 
MoveToAttribute(string name, string namespaceUri)310         public override bool MoveToAttribute(string name, string namespaceUri)
311         {
312             return this.reader.MoveToAttribute(name, namespaceUri);
313         }
314 
MoveToElement()315         public override bool MoveToElement()
316         {
317             return this.reader.MoveToElement();
318         }
319 
MoveToFirstAttribute()320         public override bool MoveToFirstAttribute()
321         {
322             return this.reader.MoveToFirstAttribute();
323         }
324 
MoveToNextAttribute()325         public override bool MoveToNextAttribute()
326         {
327             return this.reader.MoveToNextAttribute();
328         }
329 
Read()330         public override bool Read()
331         {
332             return this.reader.Read();
333         }
334 
ReadAttributeValue()335         public override bool ReadAttributeValue()
336         {
337             return this.reader.ReadAttributeValue();
338         }
339 
ReadElementString(string name)340         public override string ReadElementString(string name)
341         {
342             return this.reader.ReadElementString(name);
343         }
344 
ReadElementString(string localName, string namespaceUri)345         public override string ReadElementString(string localName, string namespaceUri)
346         {
347             return this.reader.ReadElementString(localName, namespaceUri);
348         }
349 
ReadInnerXml()350         public override string ReadInnerXml()
351         {
352             return this.reader.ReadInnerXml();
353         }
354 
ReadOuterXml()355         public override string ReadOuterXml()
356         {
357             return this.reader.ReadOuterXml();
358         }
359 
ReadStartElement(string name)360         public override void ReadStartElement(string name)
361         {
362             this.reader.ReadStartElement(name);
363         }
364 
ReadStartElement(string localName, string namespaceUri)365         public override void ReadStartElement(string localName, string namespaceUri)
366         {
367             this.reader.ReadStartElement(localName, namespaceUri);
368         }
369 
ReadEndElement()370         public override void ReadEndElement()
371         {
372             this.reader.ReadEndElement();
373         }
374 
ReadString()375         public override string ReadString()
376         {
377             return this.reader.ReadString();
378         }
379 
ResolveEntity()380         public override void ResolveEntity()
381         {
382             this.reader.ResolveEntity();
383         }
384 
ReadElementContentAsBase64(byte[] buffer, int offset, int count)385         public override int ReadElementContentAsBase64(byte[] buffer, int offset, int count)
386         {
387             return this.reader.ReadElementContentAsBase64(buffer, offset, count);
388         }
389 
ReadContentAsBase64(byte[] buffer, int offset, int count)390         public override int ReadContentAsBase64(byte[] buffer, int offset, int count)
391         {
392             return this.reader.ReadContentAsBase64(buffer, offset, count);
393         }
394 
ReadElementContentAsBinHex(byte[] buffer, int offset, int count)395         public override int ReadElementContentAsBinHex(byte[] buffer, int offset, int count)
396         {
397             return this.reader.ReadElementContentAsBinHex(buffer, offset, count);
398         }
399 
ReadContentAsBinHex(byte[] buffer, int offset, int count)400         public override int ReadContentAsBinHex(byte[] buffer, int offset, int count)
401         {
402             return this.reader.ReadContentAsBinHex(buffer, offset, count);
403         }
404 
ReadValueChunk(char[] chars, int offset, int count)405         public override int ReadValueChunk(char[] chars, int offset, int count)
406         {
407             return this.reader.ReadValueChunk(chars, offset, count);
408         }
409 
ReadContentAsBoolean()410         public override bool ReadContentAsBoolean()
411         {
412             return this.reader.ReadContentAsBoolean();
413         }
414 
ReadContentAsDateTime()415         public override DateTime ReadContentAsDateTime()
416         {
417             return this.reader.ReadContentAsDateTime();
418         }
419 
ReadContentAsDecimal()420         public override decimal ReadContentAsDecimal()
421         {
422             return (decimal)this.reader.ReadContentAs(typeof(decimal), null);
423         }
424 
ReadContentAsDouble()425         public override double ReadContentAsDouble()
426         {
427             return this.reader.ReadContentAsDouble();
428         }
429 
ReadContentAsInt()430         public override int ReadContentAsInt()
431         {
432             return this.reader.ReadContentAsInt();
433         }
434 
ReadContentAsLong()435         public override long ReadContentAsLong()
436         {
437             return this.reader.ReadContentAsLong();
438         }
439 
ReadContentAsFloat()440         public override float ReadContentAsFloat()
441         {
442             return this.reader.ReadContentAsFloat();
443         }
444 
ReadContentAsString()445         public override string ReadContentAsString()
446         {
447             return this.reader.ReadContentAsString();
448         }
449 
ReadContentAs(Type valueType, IXmlNamespaceResolver namespaceResolver)450         public override object ReadContentAs(Type valueType, IXmlNamespaceResolver namespaceResolver)
451         {
452             return this.reader.ReadContentAs(valueType, namespaceResolver);
453         }
454 
HasLineInfo()455         public bool HasLineInfo()
456         {
457             IXmlLineInfo lineInfo = this.reader as IXmlLineInfo;
458 
459             if (lineInfo == null)
460             {
461                 return false;
462             }
463 
464             return lineInfo.HasLineInfo();
465         }
466     }
467 }
468