1010using System . Diagnostics ;
1111using System . IO ;
1212using System . Linq ;
13+ using System . Text ;
1314using System . Xml ;
1415
1516namespace DocumentFormat . OpenXml
@@ -26,14 +27,10 @@ public class OpenXmlPartReader : OpenXmlReader
2627 private readonly List < KeyValuePair < string , string > > _nsDecls = new List < KeyValuePair < string , string > > ( ) ;
2728 private readonly Stack < OpenXmlElement > _elementStack = new Stack < OpenXmlElement > ( ) ;
2829
29- [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
30- private readonly string ? _encoding ;
31-
32- [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
33- private readonly bool ? _standalone ;
34-
3530 private ElementState _elementState ;
3631
32+ private OpenXmlPartReaderState ? _openXmlPartReaderState ;
33+
3734 /// <summary>
3835 /// Initializes a new instance of the OpenXmlPartReader class using the supplied OpenXmlPart class.
3936 /// </summary>
@@ -100,7 +97,8 @@ public OpenXmlPartReader(Stream partStream, IFeatureCollection features, OpenXml
10097
10198 _resolver = features . GetRequired < IOpenXmlNamespaceResolver > ( ) ;
10299 _rootElements = features . GetRequired < IRootElementFeature > ( ) ;
103- _xmlReader = CreateReader ( partStream , options . CloseStream , options . MaxCharactersInPart , ignoreWhitespace : options . IgnoreWhitespace , out _standalone , out _encoding ) ;
100+ _xmlReader = CreateReader ( partStream , options . CloseStream , options . MaxCharactersInPart , ignoreWhitespace : options . IgnoreWhitespace , out bool ? standalone , out string ? encoding ) ;
101+ _openXmlPartReaderState = new OpenXmlPartReaderState ( standalone , encoding ) ;
104102 }
105103
106104 /// <summary>
@@ -114,7 +112,8 @@ public override string? Encoding
114112 get
115113 {
116114 ThrowIfObjectDisposed ( ) ;
117- return _encoding ;
115+
116+ return _openXmlPartReaderState ? . Encoding ;
118117 }
119118 }
120119
@@ -129,7 +128,7 @@ public override bool? StandaloneXml
129128
130129 // default is true for standalone
131130 // <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
132- return _standalone ;
131+ return _openXmlPartReaderState ? . StandaloneXml ;
133132 }
134133 }
135134
0 commit comments