10
10
using System . Diagnostics ;
11
11
using System . IO ;
12
12
using System . Linq ;
13
+ using System . Text ;
13
14
using System . Xml ;
14
15
15
16
namespace DocumentFormat . OpenXml
@@ -26,14 +27,10 @@ public class OpenXmlPartReader : OpenXmlReader
26
27
private readonly List < KeyValuePair < string , string > > _nsDecls = new List < KeyValuePair < string , string > > ( ) ;
27
28
private readonly Stack < OpenXmlElement > _elementStack = new Stack < OpenXmlElement > ( ) ;
28
29
29
- [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
30
- private readonly string ? _encoding ;
31
-
32
- [ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
33
- private readonly bool ? _standalone ;
34
-
35
30
private ElementState _elementState ;
36
31
32
+ private OpenXmlPartReaderState ? _openXmlPartReaderState ;
33
+
37
34
/// <summary>
38
35
/// Initializes a new instance of the OpenXmlPartReader class using the supplied OpenXmlPart class.
39
36
/// </summary>
@@ -100,7 +97,8 @@ public OpenXmlPartReader(Stream partStream, IFeatureCollection features, OpenXml
100
97
101
98
_resolver = features . GetRequired < IOpenXmlNamespaceResolver > ( ) ;
102
99
_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 ) ;
104
102
}
105
103
106
104
/// <summary>
@@ -114,7 +112,8 @@ public override string? Encoding
114
112
get
115
113
{
116
114
ThrowIfObjectDisposed ( ) ;
117
- return _encoding ;
115
+
116
+ return _openXmlPartReaderState ? . Encoding ;
118
117
}
119
118
}
120
119
@@ -129,7 +128,7 @@ public override bool? StandaloneXml
129
128
130
129
// default is true for standalone
131
130
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
132
- return _standalone ;
131
+ return _openXmlPartReaderState ? . StandaloneXml ;
133
132
}
134
133
}
135
134
0 commit comments