XmlReaderDelegator.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.Runtime.Serialization
  5. {
  6. using System;
  7. using System.Diagnostics.CodeAnalysis;
  8. using System.Xml;
  9. using System.Xml.Schema;
  10. using System.Xml.Serialization;
  11. using System.Reflection;
  12. using System.Globalization;
  13. using System.Collections.Generic;
  14. #if USE_REFEMIT
  15. public class XmlReaderDelegator
  16. #else
  17. internal class XmlReaderDelegator
  18. #endif
  19. {
  20. protected XmlReader reader;
  21. protected XmlDictionaryReader dictionaryReader;
  22. protected bool isEndOfEmptyElement = false;
  23. public XmlReaderDelegator(XmlReader reader)
  24. {
  25. XmlObjectSerializer.CheckNull(reader, "reader");
  26. this.reader = reader;
  27. this.dictionaryReader = reader as XmlDictionaryReader;
  28. }
  29. internal XmlReader UnderlyingReader
  30. {
  31. get { return reader; }
  32. }
  33. internal ExtensionDataReader UnderlyingExtensionDataReader
  34. {
  35. get { return reader as ExtensionDataReader; }
  36. }
  37. internal int AttributeCount
  38. {
  39. get { return isEndOfEmptyElement ? 0 : reader.AttributeCount; }
  40. }
  41. internal string GetAttribute(string name)
  42. {
  43. return isEndOfEmptyElement ? null : reader.GetAttribute(name);
  44. }
  45. internal string GetAttribute(string name, string namespaceUri)
  46. {
  47. return isEndOfEmptyElement ? null : reader.GetAttribute(name, namespaceUri);
  48. }
  49. internal string GetAttribute(int i)
  50. {
  51. if (isEndOfEmptyElement)
  52. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("i", SR.GetString(SR.XmlElementAttributes)));
  53. return reader.GetAttribute(i);
  54. }
  55. internal bool IsEmptyElement
  56. {
  57. get { return false; }
  58. }
  59. internal bool IsNamespaceURI(string ns)
  60. {
  61. if (dictionaryReader == null)
  62. return ns == reader.NamespaceURI;
  63. else
  64. return dictionaryReader.IsNamespaceUri(ns);
  65. }
  66. internal bool IsLocalName(string localName)
  67. {
  68. if (dictionaryReader == null)
  69. return localName == reader.LocalName;
  70. else
  71. return dictionaryReader.IsLocalName(localName);
  72. }
  73. internal bool IsNamespaceUri(XmlDictionaryString ns)
  74. {
  75. if (dictionaryReader == null)
  76. return ns.Value == reader.NamespaceURI;
  77. else
  78. return dictionaryReader.IsNamespaceUri(ns);
  79. }
  80. internal bool IsLocalName(XmlDictionaryString localName)
  81. {
  82. if (dictionaryReader == null)
  83. return localName.Value == reader.LocalName;
  84. else
  85. return dictionaryReader.IsLocalName(localName);
  86. }
  87. internal int IndexOfLocalName(XmlDictionaryString[] localNames, XmlDictionaryString ns)
  88. {
  89. if (dictionaryReader != null)
  90. return dictionaryReader.IndexOfLocalName(localNames, ns);
  91. if (reader.NamespaceURI == ns.Value)
  92. {
  93. string localName = this.LocalName;
  94. for (int i = 0; i < localNames.Length; i++)
  95. {
  96. if (localName == localNames[i].Value)
  97. {
  98. return i;
  99. }
  100. }
  101. }
  102. return -1;
  103. }
  104. public bool IsStartElement()
  105. {
  106. return !isEndOfEmptyElement && reader.IsStartElement();
  107. }
  108. internal bool IsStartElement(string localname, string ns)
  109. {
  110. return !isEndOfEmptyElement && reader.IsStartElement(localname, ns);
  111. }
  112. public bool IsStartElement(XmlDictionaryString localname, XmlDictionaryString ns)
  113. {
  114. if (dictionaryReader == null)
  115. return !isEndOfEmptyElement && reader.IsStartElement(localname.Value, ns.Value);
  116. else
  117. return !isEndOfEmptyElement && dictionaryReader.IsStartElement(localname, ns);
  118. }
  119. internal bool MoveToAttribute(string name)
  120. {
  121. return isEndOfEmptyElement ? false : reader.MoveToAttribute(name);
  122. }
  123. internal bool MoveToAttribute(string name, string ns)
  124. {
  125. return isEndOfEmptyElement ? false : reader.MoveToAttribute(name, ns);
  126. }
  127. internal void MoveToAttribute(int i)
  128. {
  129. if (isEndOfEmptyElement)
  130. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("i", SR.GetString(SR.XmlElementAttributes)));
  131. reader.MoveToAttribute(i);
  132. }
  133. internal bool MoveToElement()
  134. {
  135. return isEndOfEmptyElement ? false : reader.MoveToElement();
  136. }
  137. internal bool MoveToFirstAttribute()
  138. {
  139. return isEndOfEmptyElement ? false : reader.MoveToFirstAttribute();
  140. }
  141. internal bool MoveToNextAttribute()
  142. {
  143. return isEndOfEmptyElement ? false : reader.MoveToNextAttribute();
  144. }
  145. public XmlNodeType NodeType
  146. {
  147. get { return isEndOfEmptyElement ? XmlNodeType.EndElement : reader.NodeType; }
  148. }
  149. internal bool Read()
  150. {
  151. //reader.MoveToFirstAttribute();
  152. //if (NodeType == XmlNodeType.Attribute)
  153. reader.MoveToElement();
  154. if (!reader.IsEmptyElement)
  155. return reader.Read();
  156. if (isEndOfEmptyElement)
  157. {
  158. isEndOfEmptyElement = false;
  159. return reader.Read();
  160. }
  161. isEndOfEmptyElement = true;
  162. return true;
  163. }
  164. #if USE_REFEMIT
  165. public XmlNodeType MoveToContent()
  166. #else
  167. internal XmlNodeType MoveToContent()
  168. #endif
  169. {
  170. if (isEndOfEmptyElement)
  171. return XmlNodeType.EndElement;
  172. return reader.MoveToContent();
  173. }
  174. internal bool ReadAttributeValue()
  175. {
  176. return isEndOfEmptyElement ? false : reader.ReadAttributeValue();
  177. }
  178. public void ReadEndElement()
  179. {
  180. if (isEndOfEmptyElement)
  181. Read();
  182. else
  183. reader.ReadEndElement();
  184. }
  185. Exception CreateInvalidPrimitiveTypeException(Type type)
  186. {
  187. return new InvalidDataContractException(SR.GetString(
  188. type.IsInterface ? SR.InterfaceTypeCannotBeCreated : SR.InvalidPrimitiveType,
  189. DataContract.GetClrTypeFullName(type)));
  190. }
  191. public object ReadElementContentAsAnyType(Type valueType)
  192. {
  193. Read();
  194. object o = ReadContentAsAnyType(valueType);
  195. ReadEndElement();
  196. return o;
  197. }
  198. internal object ReadContentAsAnyType(Type valueType)
  199. {
  200. switch (Type.GetTypeCode(valueType))
  201. {
  202. case TypeCode.Boolean:
  203. return ReadContentAsBoolean();
  204. case TypeCode.Char:
  205. return ReadContentAsChar();
  206. case TypeCode.Byte:
  207. return ReadContentAsUnsignedByte();
  208. case TypeCode.Int16:
  209. return ReadContentAsShort();
  210. case TypeCode.Int32:
  211. return ReadContentAsInt();
  212. case TypeCode.Int64:
  213. return ReadContentAsLong();
  214. case TypeCode.Single:
  215. return ReadContentAsSingle();
  216. case TypeCode.Double:
  217. return ReadContentAsDouble();
  218. case TypeCode.Decimal:
  219. return ReadContentAsDecimal();
  220. case TypeCode.DateTime:
  221. return ReadContentAsDateTime();
  222. case TypeCode.String:
  223. return ReadContentAsString();
  224. case TypeCode.SByte:
  225. return ReadContentAsSignedByte();
  226. case TypeCode.UInt16:
  227. return ReadContentAsUnsignedShort();
  228. case TypeCode.UInt32:
  229. return ReadContentAsUnsignedInt();
  230. case TypeCode.UInt64:
  231. return ReadContentAsUnsignedLong();
  232. case TypeCode.Empty:
  233. case TypeCode.DBNull:
  234. case TypeCode.Object:
  235. default:
  236. if (valueType == Globals.TypeOfByteArray)
  237. return ReadContentAsBase64();
  238. else if (valueType == Globals.TypeOfObject)
  239. return new object();
  240. else if (valueType == Globals.TypeOfTimeSpan)
  241. return ReadContentAsTimeSpan();
  242. else if (valueType == Globals.TypeOfGuid)
  243. return ReadContentAsGuid();
  244. else if (valueType == Globals.TypeOfUri)
  245. return ReadContentAsUri();
  246. else if (valueType == Globals.TypeOfXmlQualifiedName)
  247. return ReadContentAsQName();
  248. break;
  249. }
  250. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
  251. }
  252. internal IDataNode ReadExtensionData(Type valueType)
  253. {
  254. switch (Type.GetTypeCode(valueType))
  255. {
  256. case TypeCode.Boolean:
  257. return new DataNode<bool>(ReadContentAsBoolean());
  258. case TypeCode.Char:
  259. return new DataNode<char>(ReadContentAsChar());
  260. case TypeCode.Byte:
  261. return new DataNode<byte>(ReadContentAsUnsignedByte());
  262. case TypeCode.Int16:
  263. return new DataNode<short>(ReadContentAsShort());
  264. case TypeCode.Int32:
  265. return new DataNode<int>(ReadContentAsInt());
  266. case TypeCode.Int64:
  267. return new DataNode<long>(ReadContentAsLong());
  268. case TypeCode.Single:
  269. return new DataNode<float>(ReadContentAsSingle());
  270. case TypeCode.Double:
  271. return new DataNode<double>(ReadContentAsDouble());
  272. case TypeCode.Decimal:
  273. return new DataNode<decimal>(ReadContentAsDecimal());
  274. case TypeCode.DateTime:
  275. return new DataNode<DateTime>(ReadContentAsDateTime());
  276. case TypeCode.String:
  277. return new DataNode<string>(ReadContentAsString());
  278. case TypeCode.SByte:
  279. return new DataNode<sbyte>(ReadContentAsSignedByte());
  280. case TypeCode.UInt16:
  281. return new DataNode<ushort>(ReadContentAsUnsignedShort());
  282. case TypeCode.UInt32:
  283. return new DataNode<uint>(ReadContentAsUnsignedInt());
  284. case TypeCode.UInt64:
  285. return new DataNode<ulong>(ReadContentAsUnsignedLong());
  286. case TypeCode.Empty:
  287. case TypeCode.DBNull:
  288. case TypeCode.Object:
  289. default:
  290. if (valueType == Globals.TypeOfByteArray)
  291. return new DataNode<byte[]>(ReadContentAsBase64());
  292. else if (valueType == Globals.TypeOfObject)
  293. return new DataNode<object>(new object());
  294. else if (valueType == Globals.TypeOfTimeSpan)
  295. return new DataNode<TimeSpan>(ReadContentAsTimeSpan());
  296. else if (valueType == Globals.TypeOfGuid)
  297. return new DataNode<Guid>(ReadContentAsGuid());
  298. else if (valueType == Globals.TypeOfUri)
  299. return new DataNode<Uri>(ReadContentAsUri());
  300. else if (valueType == Globals.TypeOfXmlQualifiedName)
  301. return new DataNode<XmlQualifiedName>(ReadContentAsQName());
  302. break;
  303. }
  304. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidPrimitiveTypeException(valueType));
  305. }
  306. void ThrowConversionException(string value, string type)
  307. {
  308. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(XmlObjectSerializer.TryAddLineInfo(this, SR.GetString(SR.XmlInvalidConversion, value, type))));
  309. }
  310. void ThrowNotAtElement()
  311. {
  312. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.XmlStartElementExpected, "EndElement")));
  313. }
  314. #if USE_REFEMIT
  315. public virtual char ReadElementContentAsChar()
  316. #else
  317. internal virtual char ReadElementContentAsChar()
  318. #endif
  319. {
  320. return ToChar(ReadElementContentAsInt());
  321. }
  322. internal virtual char ReadContentAsChar()
  323. {
  324. return ToChar(ReadContentAsInt());
  325. }
  326. char ToChar(int value)
  327. {
  328. if (value < char.MinValue || value > char.MaxValue)
  329. {
  330. ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "Char");
  331. }
  332. return (char)value;
  333. }
  334. public string ReadElementContentAsString()
  335. {
  336. if (isEndOfEmptyElement)
  337. ThrowNotAtElement();
  338. return reader.ReadElementContentAsString();
  339. }
  340. internal string ReadContentAsString()
  341. {
  342. return isEndOfEmptyElement ? String.Empty : reader.ReadContentAsString();
  343. }
  344. public bool ReadElementContentAsBoolean()
  345. {
  346. if (isEndOfEmptyElement)
  347. ThrowNotAtElement();
  348. return reader.ReadElementContentAsBoolean();
  349. }
  350. internal bool ReadContentAsBoolean()
  351. {
  352. if (isEndOfEmptyElement)
  353. ThrowConversionException(string.Empty, "Boolean");
  354. return reader.ReadContentAsBoolean();
  355. }
  356. public float ReadElementContentAsFloat()
  357. {
  358. if (isEndOfEmptyElement)
  359. ThrowNotAtElement();
  360. return reader.ReadElementContentAsFloat();
  361. }
  362. internal float ReadContentAsSingle()
  363. {
  364. if (isEndOfEmptyElement)
  365. ThrowConversionException(string.Empty, "Float");
  366. return reader.ReadContentAsFloat();
  367. }
  368. public double ReadElementContentAsDouble()
  369. {
  370. if (isEndOfEmptyElement)
  371. ThrowNotAtElement();
  372. return reader.ReadElementContentAsDouble();
  373. }
  374. internal double ReadContentAsDouble()
  375. {
  376. if (isEndOfEmptyElement)
  377. ThrowConversionException(string.Empty, "Double");
  378. return reader.ReadContentAsDouble();
  379. }
  380. public decimal ReadElementContentAsDecimal()
  381. {
  382. if (isEndOfEmptyElement)
  383. ThrowNotAtElement();
  384. return reader.ReadElementContentAsDecimal();
  385. }
  386. internal decimal ReadContentAsDecimal()
  387. {
  388. if (isEndOfEmptyElement)
  389. ThrowConversionException(string.Empty, "Decimal");
  390. return reader.ReadContentAsDecimal();
  391. }
  392. #if USE_REFEMIT
  393. public virtual byte[] ReadElementContentAsBase64()
  394. #else
  395. internal virtual byte[] ReadElementContentAsBase64()
  396. #endif
  397. {
  398. if (isEndOfEmptyElement)
  399. ThrowNotAtElement();
  400. if (dictionaryReader == null)
  401. {
  402. return ReadContentAsBase64(reader.ReadElementContentAsString());
  403. }
  404. else
  405. {
  406. return dictionaryReader.ReadElementContentAsBase64();
  407. }
  408. }
  409. #if USE_REFEMIT
  410. public virtual byte[] ReadContentAsBase64()
  411. #else
  412. internal virtual byte[] ReadContentAsBase64()
  413. #endif
  414. {
  415. if (isEndOfEmptyElement)
  416. return new byte[0];
  417. if (dictionaryReader == null)
  418. {
  419. return ReadContentAsBase64(reader.ReadContentAsString());
  420. }
  421. else
  422. {
  423. return dictionaryReader.ReadContentAsBase64();
  424. }
  425. }
  426. internal byte[] ReadContentAsBase64(string str)
  427. {
  428. if (str == null)
  429. return null;
  430. str = str.Trim();
  431. if (str.Length == 0)
  432. return new byte[0];
  433. try
  434. {
  435. return Convert.FromBase64String(str);
  436. }
  437. catch (ArgumentException exception)
  438. {
  439. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
  440. }
  441. catch (FormatException exception)
  442. {
  443. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "byte[]", exception));
  444. }
  445. }
  446. #if USE_REFEMIT
  447. public virtual DateTime ReadElementContentAsDateTime()
  448. #else
  449. internal virtual DateTime ReadElementContentAsDateTime()
  450. #endif
  451. {
  452. if (isEndOfEmptyElement)
  453. ThrowNotAtElement();
  454. return reader.ReadElementContentAsDateTime();
  455. }
  456. internal virtual DateTime ReadContentAsDateTime()
  457. {
  458. if (isEndOfEmptyElement)
  459. ThrowConversionException(string.Empty, "DateTime");
  460. return reader.ReadContentAsDateTime();
  461. }
  462. public int ReadElementContentAsInt()
  463. {
  464. if (isEndOfEmptyElement)
  465. ThrowNotAtElement();
  466. return reader.ReadElementContentAsInt();
  467. }
  468. internal int ReadContentAsInt()
  469. {
  470. if (isEndOfEmptyElement)
  471. ThrowConversionException(string.Empty, "Int32");
  472. return reader.ReadContentAsInt();
  473. }
  474. public long ReadElementContentAsLong()
  475. {
  476. if (isEndOfEmptyElement)
  477. ThrowNotAtElement();
  478. return reader.ReadElementContentAsLong();
  479. }
  480. internal long ReadContentAsLong()
  481. {
  482. if (isEndOfEmptyElement)
  483. ThrowConversionException(string.Empty, "Int64");
  484. return reader.ReadContentAsLong();
  485. }
  486. public short ReadElementContentAsShort()
  487. {
  488. return ToShort(ReadElementContentAsInt());
  489. }
  490. internal short ReadContentAsShort()
  491. {
  492. return ToShort(ReadContentAsInt());
  493. }
  494. short ToShort(int value)
  495. {
  496. if (value < short.MinValue || value > short.MaxValue)
  497. {
  498. ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "Int16");
  499. }
  500. return (short)value;
  501. }
  502. public byte ReadElementContentAsUnsignedByte()
  503. {
  504. return ToByte(ReadElementContentAsInt());
  505. }
  506. internal byte ReadContentAsUnsignedByte()
  507. {
  508. return ToByte(ReadContentAsInt());
  509. }
  510. byte ToByte(int value)
  511. {
  512. if (value < byte.MinValue || value > byte.MaxValue)
  513. {
  514. ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "Byte");
  515. }
  516. return (byte)value;
  517. }
  518. #if USE_REFEMIT
  519. [CLSCompliant(false)]
  520. #endif
  521. public SByte ReadElementContentAsSignedByte()
  522. {
  523. return ToSByte(ReadElementContentAsInt());
  524. }
  525. internal SByte ReadContentAsSignedByte()
  526. {
  527. return ToSByte(ReadContentAsInt());
  528. }
  529. SByte ToSByte(int value)
  530. {
  531. if (value < SByte.MinValue || value > SByte.MaxValue)
  532. {
  533. ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "SByte");
  534. }
  535. return (SByte)value;
  536. }
  537. #if USE_REFEMIT
  538. [CLSCompliant(false)]
  539. #endif
  540. public UInt32 ReadElementContentAsUnsignedInt()
  541. {
  542. return ToUInt32(ReadElementContentAsLong());
  543. }
  544. internal UInt32 ReadContentAsUnsignedInt()
  545. {
  546. return ToUInt32(ReadContentAsLong());
  547. }
  548. UInt32 ToUInt32(long value)
  549. {
  550. if (value < UInt32.MinValue || value > UInt32.MaxValue)
  551. {
  552. ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "UInt32");
  553. }
  554. return (UInt32)value;
  555. }
  556. #if USE_REFEMIT
  557. [CLSCompliant(false)]
  558. public virtual UInt64 ReadElementContentAsUnsignedLong()
  559. #else
  560. internal virtual UInt64 ReadElementContentAsUnsignedLong()
  561. #endif
  562. {
  563. if (isEndOfEmptyElement)
  564. ThrowNotAtElement();
  565. string str = reader.ReadElementContentAsString();
  566. if (str == null || str.Length == 0)
  567. ThrowConversionException(string.Empty, "UInt64");
  568. return XmlConverter.ToUInt64(str);
  569. }
  570. internal virtual UInt64 ReadContentAsUnsignedLong()
  571. {
  572. string str = reader.ReadContentAsString();
  573. if (str == null || str.Length == 0)
  574. ThrowConversionException(string.Empty, "UInt64");
  575. return XmlConverter.ToUInt64(str);
  576. }
  577. #if USE_REFEMIT
  578. [CLSCompliant(false)]
  579. #endif
  580. public UInt16 ReadElementContentAsUnsignedShort()
  581. {
  582. return ToUInt16(ReadElementContentAsInt());
  583. }
  584. internal UInt16 ReadContentAsUnsignedShort()
  585. {
  586. return ToUInt16(ReadContentAsInt());
  587. }
  588. UInt16 ToUInt16(int value)
  589. {
  590. if (value < UInt16.MinValue || value > UInt16.MaxValue)
  591. {
  592. ThrowConversionException(value.ToString(NumberFormatInfo.CurrentInfo), "UInt16");
  593. }
  594. return (UInt16)value;
  595. }
  596. public TimeSpan ReadElementContentAsTimeSpan()
  597. {
  598. if (isEndOfEmptyElement)
  599. ThrowNotAtElement();
  600. string str = reader.ReadElementContentAsString();
  601. return XmlConverter.ToTimeSpan(str);
  602. }
  603. internal TimeSpan ReadContentAsTimeSpan()
  604. {
  605. string str = reader.ReadContentAsString();
  606. return XmlConverter.ToTimeSpan(str);
  607. }
  608. [SuppressMessage("Reliability", "Reliability113", Justification = "Catching expected exceptions inline instead of calling Fx.CreateGuid to minimize code change")]
  609. public Guid ReadElementContentAsGuid()
  610. {
  611. if (isEndOfEmptyElement)
  612. ThrowNotAtElement();
  613. string str = reader.ReadElementContentAsString();
  614. try
  615. {
  616. return Guid.Parse(str);
  617. }
  618. catch (ArgumentException exception)
  619. {
  620. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
  621. }
  622. catch (FormatException exception)
  623. {
  624. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
  625. }
  626. catch (OverflowException exception)
  627. {
  628. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
  629. }
  630. }
  631. [SuppressMessage("Reliability", "Reliability113", Justification = "Catching expected exceptions inline instead of calling Fx.CreateGuid to minimize code change")]
  632. internal Guid ReadContentAsGuid()
  633. {
  634. string str = reader.ReadContentAsString();
  635. try
  636. {
  637. return Guid.Parse(str);
  638. }
  639. catch (ArgumentException exception)
  640. {
  641. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
  642. }
  643. catch (FormatException exception)
  644. {
  645. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
  646. }
  647. catch (OverflowException exception)
  648. {
  649. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Guid", exception));
  650. }
  651. }
  652. public Uri ReadElementContentAsUri()
  653. {
  654. if (isEndOfEmptyElement)
  655. ThrowNotAtElement();
  656. string str = ReadElementContentAsString();
  657. try
  658. {
  659. return new Uri(str, UriKind.RelativeOrAbsolute);
  660. }
  661. catch (ArgumentException exception)
  662. {
  663. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
  664. }
  665. catch (FormatException exception)
  666. {
  667. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
  668. }
  669. }
  670. internal Uri ReadContentAsUri()
  671. {
  672. string str = ReadContentAsString();
  673. try
  674. {
  675. return new Uri(str, UriKind.RelativeOrAbsolute);
  676. }
  677. catch (ArgumentException exception)
  678. {
  679. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
  680. }
  681. catch (FormatException exception)
  682. {
  683. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlExceptionHelper.CreateConversionException(str, "Uri", exception));
  684. }
  685. }
  686. public XmlQualifiedName ReadElementContentAsQName()
  687. {
  688. Read();
  689. XmlQualifiedName obj = ReadContentAsQName();
  690. ReadEndElement();
  691. return obj;
  692. }
  693. internal virtual XmlQualifiedName ReadContentAsQName()
  694. {
  695. return ParseQualifiedName(ReadContentAsString());
  696. }
  697. XmlQualifiedName ParseQualifiedName(string str)
  698. {
  699. string name, ns, prefix;
  700. if (str == null || str.Length == 0)
  701. name = ns = String.Empty;
  702. else
  703. XmlObjectSerializerReadContext.ParseQualifiedName(str, this, out name, out ns, out prefix);
  704. return new XmlQualifiedName(name, ns);
  705. }
  706. void CheckExpectedArrayLength(XmlObjectSerializerReadContext context, int arrayLength)
  707. {
  708. #if NO
  709. int readerArrayLength;
  710. if (dictionaryReader.TryGetArrayLength(out readerArrayLength))
  711. {
  712. if (readerArrayLength != arrayLength)
  713. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.ArraySizeXmlMismatch, arrayLength, readerArrayLength)));
  714. }
  715. #endif
  716. context.IncrementItemCount(arrayLength);
  717. }
  718. protected int GetArrayLengthQuota(XmlObjectSerializerReadContext context)
  719. {
  720. if (dictionaryReader.Quotas == null)
  721. return context.RemainingItemCount;
  722. return Math.Min(context.RemainingItemCount, dictionaryReader.Quotas.MaxArrayLength);
  723. }
  724. void CheckActualArrayLength(int expectedLength, int actualLength, XmlDictionaryString itemName, XmlDictionaryString itemNamespace)
  725. {
  726. if (expectedLength != actualLength)
  727. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.ArrayExceededSizeAttribute, expectedLength, itemName.Value, itemNamespace.Value)));
  728. }
  729. internal bool TryReadBooleanArray(XmlObjectSerializerReadContext context,
  730. XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
  731. int arrayLength, out bool[] array)
  732. {
  733. if (dictionaryReader == null)
  734. {
  735. array = null;
  736. return false;
  737. }
  738. if (arrayLength != -1)
  739. {
  740. CheckExpectedArrayLength(context, arrayLength);
  741. array = new bool[arrayLength];
  742. int read = 0, offset = 0;
  743. while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
  744. {
  745. offset += read;
  746. }
  747. CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
  748. }
  749. else
  750. {
  751. array = BooleanArrayHelperWithDictionaryString.Instance.ReadArray(
  752. dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
  753. context.IncrementItemCount(array.Length);
  754. }
  755. return true;
  756. }
  757. internal bool TryReadDateTimeArray(XmlObjectSerializerReadContext context,
  758. XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
  759. int arrayLength, out DateTime[] array)
  760. {
  761. if (dictionaryReader == null)
  762. {
  763. array = null;
  764. return false;
  765. }
  766. if (arrayLength != -1)
  767. {
  768. CheckExpectedArrayLength(context, arrayLength);
  769. array = new DateTime[arrayLength];
  770. int read = 0, offset = 0;
  771. while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
  772. {
  773. offset += read;
  774. }
  775. CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
  776. }
  777. else
  778. {
  779. array = DateTimeArrayHelperWithDictionaryString.Instance.ReadArray(
  780. dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
  781. context.IncrementItemCount(array.Length);
  782. }
  783. return true;
  784. }
  785. internal bool TryReadDecimalArray(XmlObjectSerializerReadContext context,
  786. XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
  787. int arrayLength, out decimal[] array)
  788. {
  789. if (dictionaryReader == null)
  790. {
  791. array = null;
  792. return false;
  793. }
  794. if (arrayLength != -1)
  795. {
  796. CheckExpectedArrayLength(context, arrayLength);
  797. array = new decimal[arrayLength];
  798. int read = 0, offset = 0;
  799. while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
  800. {
  801. offset += read;
  802. }
  803. CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
  804. }
  805. else
  806. {
  807. array = DecimalArrayHelperWithDictionaryString.Instance.ReadArray(
  808. dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
  809. context.IncrementItemCount(array.Length);
  810. }
  811. return true;
  812. }
  813. internal bool TryReadInt32Array(XmlObjectSerializerReadContext context,
  814. XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
  815. int arrayLength, out int[] array)
  816. {
  817. if (dictionaryReader == null)
  818. {
  819. array = null;
  820. return false;
  821. }
  822. if (arrayLength != -1)
  823. {
  824. CheckExpectedArrayLength(context, arrayLength);
  825. array = new int[arrayLength];
  826. int read = 0, offset = 0;
  827. while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
  828. {
  829. offset += read;
  830. }
  831. CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
  832. }
  833. else
  834. {
  835. array = Int32ArrayHelperWithDictionaryString.Instance.ReadArray(
  836. dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
  837. context.IncrementItemCount(array.Length);
  838. }
  839. return true;
  840. }
  841. internal bool TryReadInt64Array(XmlObjectSerializerReadContext context,
  842. XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
  843. int arrayLength, out long[] array)
  844. {
  845. if (dictionaryReader == null)
  846. {
  847. array = null;
  848. return false;
  849. }
  850. if (arrayLength != -1)
  851. {
  852. CheckExpectedArrayLength(context, arrayLength);
  853. array = new long[arrayLength];
  854. int read = 0, offset = 0;
  855. while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
  856. {
  857. offset += read;
  858. }
  859. CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
  860. }
  861. else
  862. {
  863. array = Int64ArrayHelperWithDictionaryString.Instance.ReadArray(
  864. dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
  865. context.IncrementItemCount(array.Length);
  866. }
  867. return true;
  868. }
  869. internal bool TryReadSingleArray(XmlObjectSerializerReadContext context,
  870. XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
  871. int arrayLength, out float[] array)
  872. {
  873. if (dictionaryReader == null)
  874. {
  875. array = null;
  876. return false;
  877. }
  878. if (arrayLength != -1)
  879. {
  880. CheckExpectedArrayLength(context, arrayLength);
  881. array = new float[arrayLength];
  882. int read = 0, offset = 0;
  883. while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
  884. {
  885. offset += read;
  886. }
  887. CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
  888. }
  889. else
  890. {
  891. array = SingleArrayHelperWithDictionaryString.Instance.ReadArray(
  892. dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
  893. context.IncrementItemCount(array.Length);
  894. }
  895. return true;
  896. }
  897. internal bool TryReadDoubleArray(XmlObjectSerializerReadContext context,
  898. XmlDictionaryString itemName, XmlDictionaryString itemNamespace,
  899. int arrayLength, out double[] array)
  900. {
  901. if (dictionaryReader == null)
  902. {
  903. array = null;
  904. return false;
  905. }
  906. if (arrayLength != -1)
  907. {
  908. CheckExpectedArrayLength(context, arrayLength);
  909. array = new double[arrayLength];
  910. int read = 0, offset = 0;
  911. while ((read = dictionaryReader.ReadArray(itemName, itemNamespace, array, offset, arrayLength - offset)) > 0)
  912. {
  913. offset += read;
  914. }
  915. CheckActualArrayLength(arrayLength, offset, itemName, itemNamespace);
  916. }
  917. else
  918. {
  919. array = DoubleArrayHelperWithDictionaryString.Instance.ReadArray(
  920. dictionaryReader, itemName, itemNamespace, GetArrayLengthQuota(context));
  921. context.IncrementItemCount(array.Length);
  922. }
  923. return true;
  924. }
  925. internal IDictionary<string, string> GetNamespacesInScope(XmlNamespaceScope scope)
  926. {
  927. return (reader is IXmlNamespaceResolver) ? ((IXmlNamespaceResolver)reader).GetNamespacesInScope(scope) : null;
  928. }
  929. // IXmlLineInfo members
  930. internal bool HasLineInfo()
  931. {
  932. IXmlLineInfo iXmlLineInfo = reader as IXmlLineInfo;
  933. return (iXmlLineInfo == null) ? false : iXmlLineInfo.HasLineInfo();
  934. }
  935. internal int LineNumber
  936. {
  937. get
  938. {
  939. IXmlLineInfo iXmlLineInfo = reader as IXmlLineInfo;
  940. return (iXmlLineInfo == null) ? 0 : iXmlLineInfo.LineNumber;
  941. }
  942. }
  943. internal int LinePosition
  944. {
  945. get
  946. {
  947. IXmlLineInfo iXmlLineInfo = reader as IXmlLineInfo;
  948. return (iXmlLineInfo == null) ? 0 : iXmlLineInfo.LinePosition;
  949. }
  950. }
  951. // IXmlTextParser members
  952. internal bool Normalized
  953. {
  954. get
  955. {
  956. XmlTextReader xmlTextReader = reader as XmlTextReader;
  957. if (xmlTextReader == null)
  958. {
  959. IXmlTextParser xmlTextParser = reader as IXmlTextParser;
  960. return (xmlTextParser == null) ? false : xmlTextParser.Normalized;
  961. }
  962. else
  963. return xmlTextReader.Normalization;
  964. }
  965. set
  966. {
  967. XmlTextReader xmlTextReader = reader as XmlTextReader;
  968. if (xmlTextReader == null)
  969. {
  970. IXmlTextParser xmlTextParser = reader as IXmlTextParser;
  971. if (xmlTextParser != null)
  972. xmlTextParser.Normalized = value;
  973. }
  974. else
  975. xmlTextReader.Normalization = value;
  976. }
  977. }
  978. internal WhitespaceHandling WhitespaceHandling
  979. {
  980. get
  981. {
  982. XmlTextReader xmlTextReader = reader as XmlTextReader;
  983. if (xmlTextReader == null)
  984. {
  985. IXmlTextParser xmlTextParser = reader as IXmlTextParser;
  986. return (xmlTextParser == null) ? WhitespaceHandling.None : xmlTextParser.WhitespaceHandling;
  987. }
  988. else
  989. return xmlTextReader.WhitespaceHandling;
  990. }
  991. set
  992. {
  993. XmlTextReader xmlTextReader = reader as XmlTextReader;
  994. if (xmlTextReader == null)
  995. {
  996. IXmlTextParser xmlTextParser = reader as IXmlTextParser;
  997. if (xmlTextParser != null)
  998. xmlTextParser.WhitespaceHandling = value;
  999. }
  1000. else
  1001. xmlTextReader.WhitespaceHandling = value;
  1002. }
  1003. }
  1004. // delegating properties and methods
  1005. internal string Name { get { return reader.Name; } }
  1006. #if USE_REFEMIT
  1007. internal string LocalName
  1008. #else
  1009. public string LocalName
  1010. #endif
  1011. {
  1012. get { return reader.LocalName; }
  1013. }
  1014. internal string NamespaceURI { get { return reader.NamespaceURI; } }
  1015. internal string Value { get { return reader.Value; } }
  1016. internal Type ValueType { get { return reader.ValueType; } }
  1017. internal int Depth { get { return reader.Depth; } }
  1018. internal string LookupNamespace(string prefix) { return reader.LookupNamespace(prefix); }
  1019. internal bool EOF { get { return reader.EOF; } }
  1020. internal void Skip()
  1021. {
  1022. reader.Skip();
  1023. isEndOfEmptyElement = false;
  1024. }
  1025. #if NotUsed
  1026. internal XmlReaderSettings Settings { get { return reader.Settings; } }
  1027. internal string Prefix { get { return reader.Prefix; } }
  1028. internal bool HasValue { get { return reader.HasValue; } }
  1029. internal string BaseURI { get { return reader.BaseURI; } }
  1030. internal bool IsDefault { get { return reader.IsDefault; } }
  1031. internal char QuoteChar { get { return reader.QuoteChar; } }
  1032. internal XmlSpace XmlSpace { get { return reader.XmlSpace; } }
  1033. internal string XmlLang { get { return reader.XmlLang; } }
  1034. internal IXmlSchemaInfo SchemaInfo { get { return reader.SchemaInfo; } }
  1035. internal string this[int i] { get { return reader[i]; } }
  1036. internal string this[string name] { get { return reader[name]; } }
  1037. internal string this[string name, string namespaceURI] { get { return reader[name, namespaceURI]; } }
  1038. internal ReadState ReadState { get { return reader.ReadState; } }
  1039. internal XmlNameTable NameTable { get { return reader.NameTable; } }
  1040. internal bool CanResolveEntity { get { return reader.CanResolveEntity; } }
  1041. internal bool CanReadBinaryContent { get { return reader.CanReadBinaryContent; } }
  1042. internal bool CanReadValueChunk { get { return reader.CanReadValueChunk; } }
  1043. internal bool HasAttributes { get { return reader.HasAttributes; } }
  1044. internal bool IsStartElement(string name) { return reader.IsStartElement(name); }
  1045. internal void ResolveEntity() { reader.ResolveEntity(); }
  1046. internal string ReadInnerXml() { return reader.ReadInnerXml(); }
  1047. internal string ReadOuterXml() { return reader.ReadOuterXml(); }
  1048. internal object ReadContentAsObject() { return reader.ReadContentAsObject(); }
  1049. internal object ReadContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver) { return reader.ReadContentAs(returnType, namespaceResolver); }
  1050. internal object ReadElementContentAsObject() { return reader.ReadElementContentAsObject(); }
  1051. internal object ReadElementContentAsObject(string localName, string namespaceURI) { return reader.ReadElementContentAsObject(localName, namespaceURI); }
  1052. internal bool ReadElementContentAsBoolean(string localName, string namespaceURI) { return reader.ReadElementContentAsBoolean(localName, namespaceURI); }
  1053. internal DateTime ReadElementContentAsDateTime(string localName, string namespaceURI) { return reader.ReadElementContentAsDateTime(localName, namespaceURI); }
  1054. internal double ReadElementContentAsDouble(string localName, string namespaceURI) { return reader.ReadElementContentAsDouble(localName, namespaceURI); }
  1055. internal int ReadElementContentAsInt(string localName, string namespaceURI) { return reader.ReadElementContentAsInt(localName, namespaceURI); }
  1056. internal long ReadElementContentAsLong(string localName, string namespaceURI) { return reader.ReadElementContentAsLong(localName, namespaceURI); }
  1057. internal string ReadElementContentAsString(string localName, string namespaceURI) { return reader.ReadElementContentAsString(localName, namespaceURI); }
  1058. internal object ReadElementContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver) { return reader.ReadElementContentAs(returnType, namespaceResolver); }
  1059. internal object ReadElementContentAs(Type returnType, IXmlNamespaceResolver namespaceResolver, string localName, string namespaceURI) { return reader.ReadElementContentAs(returnType, namespaceResolver, localName, namespaceURI); }
  1060. internal int ReadContentAsBase64(byte[] buffer, int index, int count) { return reader.ReadContentAsBase64(buffer, index, count); }
  1061. internal int ReadElementContentAsBase64(byte[] buffer, int index, int count) { return reader.ReadElementContentAsBase64(buffer, index, count); }
  1062. internal int ReadContentAsBinHex(byte[] buffer, int index, int count) { return reader.ReadContentAsBinHex(buffer, index, count); }
  1063. internal int ReadElementContentAsBinHex(byte[] buffer, int index, int count) { return reader.ReadElementContentAsBinHex(buffer, index, count); }
  1064. internal int ReadValueChunk(char[] buffer, int index, int count) { return reader.ReadValueChunk(buffer, index, count); }
  1065. internal string ReadString() { return reader.ReadString(); }
  1066. internal string ReadElementString() { return reader.ReadElementString(); }
  1067. internal string ReadElementString(string name) { return reader.ReadElementString(name); }
  1068. internal string ReadElementString(string localname, string ns) { return reader.ReadElementString(localname, ns); }
  1069. internal bool ReadToFollowing(string name) { return ReadToFollowing(name); }
  1070. internal bool ReadToFollowing(string localName, string namespaceURI) { return reader.ReadToFollowing(localName, namespaceURI); }
  1071. internal bool ReadToDescendant(string name) { return reader.ReadToDescendant(name); }
  1072. internal bool ReadToDescendant(string localName, string namespaceURI) { return reader.ReadToDescendant(localName, namespaceURI); }
  1073. internal bool ReadToNextSibling(string name) { return reader.ReadToNextSibling(name); }
  1074. internal bool ReadToNextSibling(string localName, string namespaceURI) { return reader.ReadToNextSibling(localName, namespaceURI); }
  1075. internal void ReadStartElement()
  1076. {
  1077. if (isEndOfEmptyElement)
  1078. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidNodeType, this.NodeType.ToString())));
  1079. if (reader.IsEmptyElement)
  1080. isEndOfEmptyElement = true;
  1081. else
  1082. reader.ReadStartElement();
  1083. }
  1084. internal void ReadStartElement(String localname, String ns)
  1085. {
  1086. if (isEndOfEmptyElement)
  1087. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidNodeType, this.NodeType.ToString())));
  1088. if (reader.IsEmptyElement)
  1089. isEndOfEmptyElement = true;
  1090. else
  1091. reader.ReadStartElement(localname, ns);
  1092. }
  1093. internal void ReadStartElement(string name)
  1094. {
  1095. if (isEndOfEmptyElement)
  1096. throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidNodeType, this.NodeType.ToString())));
  1097. if (reader.IsEmptyElement)
  1098. isEndOfEmptyElement = true;
  1099. else
  1100. reader.ReadStartElement(name);
  1101. }
  1102. internal XmlReader ReadSubtree()
  1103. {
  1104. if (this.NodeType == XmlNodeType.Element)
  1105. return reader.ReadSubtree();
  1106. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlFunctionRequiredNodeType, "ReadSubtree", "Element")));
  1107. }
  1108. #endif
  1109. }
  1110. }