Skip to content

Commit 24da52f

Browse files
committed
replace _standalone and _encoding with readonly struct
1 parent f990ae8 commit 24da52f

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

Diff for: src/DocumentFormat.OpenXml.Framework/OpenXmlPartReader.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Diagnostics;
1111
using System.IO;
1212
using System.Linq;
13+
using System.Text;
1314
using System.Xml;
1415

1516
namespace 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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace DocumentFormat.OpenXml;
5+
6+
internal readonly struct OpenXmlPartReaderState
7+
{
8+
internal OpenXmlPartReaderState(bool? standalone, string? encoding)
9+
{
10+
StandaloneXml = standalone;
11+
Encoding = encoding;
12+
}
13+
14+
internal string? Encoding { get; }
15+
16+
internal bool? StandaloneXml { get; }
17+
}

0 commit comments

Comments
 (0)