Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<LatestTargetFramework>net8.0</LatestTargetFramework>
<SamplesFrameworks>net8.0</SamplesFrameworks>
<SamplesFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(SamplesFrameworks);net472</SamplesFrameworks>
<DefineConstants Condition=" '$(TargetFramework)' != 'net35' And '$(TargetFramework)' != 'net40' And '$(TargetFramework)' != 'net46' And '$(TargetFramework)' != 'net472' ">$(DefineConstants);FEATURE_ASYNC_SAX_XML</DefineConstants>
</PropertyGroup>
</Otherwise>
</Choose>
Expand Down
17 changes: 8 additions & 9 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlPartReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace DocumentFormat.OpenXml
Expand All @@ -26,14 +27,10 @@ public class OpenXmlPartReader : OpenXmlReader
private readonly List<KeyValuePair<string, string>> _nsDecls = new List<KeyValuePair<string, string>>();
private readonly Stack<OpenXmlElement> _elementStack = new Stack<OpenXmlElement>();

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly string? _encoding;

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private readonly bool? _standalone;

private ElementState _elementState;

private OpenXmlPartReaderState? _openXmlPartReaderState;

/// <summary>
/// Initializes a new instance of the OpenXmlPartReader class using the supplied OpenXmlPart class.
/// </summary>
Expand Down Expand Up @@ -100,7 +97,8 @@ public OpenXmlPartReader(Stream partStream, IFeatureCollection features, OpenXml

_resolver = features.GetRequired<IOpenXmlNamespaceResolver>();
_rootElements = features.GetRequired<IRootElementFeature>();
_xmlReader = CreateReader(partStream, options.CloseStream, options.MaxCharactersInPart, ignoreWhitespace: options.IgnoreWhitespace, out _standalone, out _encoding);
_xmlReader = CreateReader(partStream, options.CloseStream, options.MaxCharactersInPart, ignoreWhitespace: options.IgnoreWhitespace, out bool? standalone, out string? encoding);
_openXmlPartReaderState = new OpenXmlPartReaderState(standalone, encoding);
}

/// <summary>
Expand All @@ -114,7 +112,8 @@ public override string? Encoding
get
{
ThrowIfObjectDisposed();
return _encoding;

return _openXmlPartReaderState?.Encoding;
}
}

Expand All @@ -129,7 +128,7 @@ public override bool? StandaloneXml

// default is true for standalone
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
return _standalone;
return _openXmlPartReaderState?.StandaloneXml;
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlPartReaderState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

Check failure on line 1 in src/DocumentFormat.OpenXml.Framework/OpenXmlPartReaderState.cs

View workflow job for this annotation

GitHub Actions / Run

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/DocumentFormat.OpenXml.Framework/OpenXmlPartReaderState.cs

View workflow job for this annotation

GitHub Actions / Run

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check warning on line 1 in src/DocumentFormat.OpenXml.Framework/OpenXmlPartReaderState.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)
using System.Collections.Generic;
using System.Text;

namespace DocumentFormat.OpenXml;

internal readonly struct OpenXmlPartReaderState
{
internal OpenXmlPartReaderState(bool? standalone, string? encoding)
{
StandaloneXml = standalone ?? true;
Encoding = encoding;
}

internal string? Encoding { get; }

internal bool? StandaloneXml { get; }
}
Loading
Loading