diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1d5a526a4..ef3196f80 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,19 +59,12 @@ jobs: fail-fast: false matrix: configuration: [ debug, release ] - projectloadstyle: [ net35, net40, All ] os: [ windows-latest, ubuntu-latest ] - exclude: - - projectloadstyle: net35 - os: ubuntu-latest - - projectloadstyle: net40 - os: ubuntu-latest env: RunPeVerify: true Solution_Name: Open-XML-SDK.slnx Configuration: ${{ matrix.configuration }} - ProjectLoadStyle: ${{ matrix.projectloadstyle }} runs-on: ${{ matrix.os }} diff --git a/Directory.Build.props b/Directory.Build.props index 5403640d8..b96bd40ac 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -32,54 +32,23 @@ $(GitVersion_NuGetVersionV2) - - - - - - $(NoWarn);CS1685 - net35 - net35 - net472 - net472 - net472 - net472 - $(DefineConstants);FEATURE_NO_VALIDATOR_CANCELLATIONTOKEN - - - - - - $(NoWarn);CS1685 - net40 - net40 - net472 - net472 - net472 - net472 - - - - - netstandard2.0;net10.0;net8.0;net35;net40;net46 - netstandard2.0;net10.0;net6.0;net8.0;net35;net40;net46 - netstandard2.0;net472 - net8.0;net10.0 - $(TestTargetFrameworks);net472 - net10.0 - net8.0;net10.0 - $(SamplesFrameworks);net472 - $(DefineConstants);FEATURE_ASYNC_SAX_XML - - - + + netstandard2.0;net10.0;net8.0;net46 + netstandard2.0;net10.0;net6.0;net8.0;net46 + netstandard2.0;net472 + net8.0;net10.0 + $(TestTargetFrameworks);net472 + net10.0 + net8.0;net10.0 + $(SamplesFrameworks);net472 + $(DefineConstants);FEATURE_ASYNC_SAX_XML + false true false - true + true diff --git a/Directory.Build.targets b/Directory.Build.targets index 10766ed3b..3eba74a0e 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -14,13 +14,6 @@ - - - CurrentArchitecture - CurrentRuntime - false - - false diff --git a/src/DocumentFormat.OpenXml.Features/RandomNumberGenerator/RandomNumberGeneratorFeatureExtensions.cs b/src/DocumentFormat.OpenXml.Features/RandomNumberGenerator/RandomNumberGeneratorFeatureExtensions.cs index 38660dab4..79511e3e6 100644 --- a/src/DocumentFormat.OpenXml.Features/RandomNumberGenerator/RandomNumberGeneratorFeatureExtensions.cs +++ b/src/DocumentFormat.OpenXml.Features/RandomNumberGenerator/RandomNumberGeneratorFeatureExtensions.cs @@ -37,9 +37,7 @@ private sealed class RandomNumberGeneratorFeature : IRandomNumberGeneratorFeatur public void Dispose() { -#if !NET35 _generator.Dispose(); -#endif } public void GetBytes(byte[] bytes) diff --git a/src/DocumentFormat.OpenXml.Framework/Framework/Cached.cs b/src/DocumentFormat.OpenXml.Framework/Framework/Cached.cs index 0e0856427..e7497d897 100644 --- a/src/DocumentFormat.OpenXml.Framework/Framework/Cached.cs +++ b/src/DocumentFormat.OpenXml.Framework/Framework/Cached.cs @@ -8,17 +8,8 @@ namespace DocumentFormat.OpenXml.Framework { internal static class Cached { -#if !NET35 && !NET40 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Array() => System.Array.Empty(); -#else - public static T[] Array() => EmptyArray.Value; - - private static class EmptyArray - { - internal static readonly T[] Value = new T[0]; - } -#endif public static ReadOnlyCollection ReadOnlyCollection() => ReadOnlyCollectionCache.Value; diff --git a/src/DocumentFormat.OpenXml.Framework/Framework/DelegatingStream.cs b/src/DocumentFormat.OpenXml.Framework/Framework/DelegatingStream.cs index f9b822fb1..6cc9c2506 100644 --- a/src/DocumentFormat.OpenXml.Framework/Framework/DelegatingStream.cs +++ b/src/DocumentFormat.OpenXml.Framework/Framework/DelegatingStream.cs @@ -5,10 +5,8 @@ using System.Diagnostics; using System.IO; -#if !NET35 && !NET40 using System.Threading; using System.Threading.Tasks; -#endif namespace DocumentFormat.OpenXml.Framework; @@ -111,12 +109,10 @@ public override int ReadByte() return _innerStream.ReadByte(); } -#if !NET35 && !NET40 public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { return _innerStream.ReadAsync(buffer, offset, count, cancellationToken); } -#endif #if NET6_0_OR_GREATER public override ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) @@ -132,12 +128,10 @@ public override void CopyTo(Stream destination, int bufferSize) } #endif -#if !NET35 && !NET40 public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) { return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken); } -#endif #endregion Read @@ -148,12 +142,10 @@ public override void Flush() _innerStream.Flush(); } -#if !NET35 && !NET40 public override Task FlushAsync(CancellationToken cancellationToken) { return _innerStream.FlushAsync(cancellationToken); } -#endif public override void SetLength(long value) { @@ -177,12 +169,10 @@ public override void WriteByte(byte value) _innerStream.WriteByte(value); } -#if !NET35 && !NET40 public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { return _innerStream.WriteAsync(buffer, offset, count, cancellationToken); } -#endif #if NET6_0_OR_GREATER public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) diff --git a/src/DocumentFormat.OpenXml.Framework/Framework/ReadOnlyStream.cs b/src/DocumentFormat.OpenXml.Framework/Framework/ReadOnlyStream.cs index a5b0152a1..a2424bb00 100644 --- a/src/DocumentFormat.OpenXml.Framework/Framework/ReadOnlyStream.cs +++ b/src/DocumentFormat.OpenXml.Framework/Framework/ReadOnlyStream.cs @@ -4,10 +4,8 @@ using System; using System.IO; -#if !NET35 && !NET40 using System.Threading; using System.Threading.Tasks; -#endif namespace DocumentFormat.OpenXml.Framework; @@ -24,9 +22,7 @@ public override void Flush() { } -#if !NET35 && !NET40 public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask; -#endif public override void SetLength(long value) => throw new NotSupportedException(); @@ -41,10 +37,8 @@ public override void Write(ReadOnlySpan buffer) public override void WriteByte(byte value) => throw new NotSupportedException(); -#if !NET35 && !NET40 public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => throw new NotSupportedException(); -#endif #if NET6_0_OR_GREATER public override ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) diff --git a/src/DocumentFormat.OpenXml.Framework/Framework/Schema/ParticlePath.cs b/src/DocumentFormat.OpenXml.Framework/Framework/Schema/ParticlePath.cs index 75c460ec8..2128dd851 100644 --- a/src/DocumentFormat.OpenXml.Framework/Framework/Schema/ParticlePath.cs +++ b/src/DocumentFormat.OpenXml.Framework/Framework/Schema/ParticlePath.cs @@ -5,10 +5,6 @@ using System; using System.Collections.Generic; -#if NET35 -using System.Linq; -#endif - namespace DocumentFormat.OpenXml.Framework.Schema { internal class ParticlePath : IComparable, IEquatable @@ -42,11 +38,7 @@ public int CompareTo(ParticlePath? other) => CompareTo(other, true); public override string ToString() -#if NET35 - => string.Join(", ", _values.Select(v => v.ToString()).ToArray()); -#else => string.Join(", ", (IEnumerable)_values); -#endif private int CompareTo(ParticlePath? other, bool isCompare) { diff --git a/src/DocumentFormat.OpenXml.Framework/OpenXmlElement.cs b/src/DocumentFormat.OpenXml.Framework/OpenXmlElement.cs index 59a63d6f7..d1ae6832f 100644 --- a/src/DocumentFormat.OpenXml.Framework/OpenXmlElement.cs +++ b/src/DocumentFormat.OpenXml.Framework/OpenXmlElement.cs @@ -1802,11 +1802,7 @@ private protected XmlReader CreateXmlReader(string outerXml) if (OpenXmlElementContext is not null) { -#if NET35 - OpenXmlElementContext.XmlReaderSettings.ProhibitDtd = true; // set true explicitly for security fix -#else OpenXmlElementContext.XmlReaderSettings.DtdProcessing = DtdProcessing.Prohibit; // set to prohibit explicitly for security fix -#endif return XmlConvertingReaderFactory.Create(stringReader, Features.GetNamespaceResolver(), OpenXmlElementContext.XmlReaderSettings); } else diff --git a/src/DocumentFormat.OpenXml.Framework/OpenXmlElementContext.cs b/src/DocumentFormat.OpenXml.Framework/OpenXmlElementContext.cs index 608e50503..9ec1fb9fa 100644 --- a/src/DocumentFormat.OpenXml.Framework/OpenXmlElementContext.cs +++ b/src/DocumentFormat.OpenXml.Framework/OpenXmlElementContext.cs @@ -70,11 +70,7 @@ internal static XmlReaderSettings CreateDefaultXmlReaderSettings() { return new XmlReaderSettings { -#if NET35 - ProhibitDtd = true, -#else DtdProcessing = DtdProcessing.Prohibit, -#endif NameTable = new NameTable(), // Set IgnoreWhitespace to false for the SDK to handle the whitespace node type. We have to do this because diff --git a/src/DocumentFormat.OpenXml.Framework/OpenXmlMiscNode.cs b/src/DocumentFormat.OpenXml.Framework/OpenXmlMiscNode.cs index 52febf1b6..0688ffec6 100644 --- a/src/DocumentFormat.OpenXml.Framework/OpenXmlMiscNode.cs +++ b/src/DocumentFormat.OpenXml.Framework/OpenXmlMiscNode.cs @@ -71,11 +71,7 @@ public OpenXmlMiscNode(XmlNodeType nodeType, string outerXml) { XmlReaderSettings settings = new XmlReaderSettings { -#if NET35 - ProhibitDtd = true, // set true explicitly for security fix -#else DtdProcessing = DtdProcessing.Prohibit, // set to prohibit explicitly for security fix -#endif }; using (XmlReader xmlReader = XmlConvertingReaderFactory.Create(stringReader, Features.GetNamespaceResolver(), settings)) @@ -121,11 +117,7 @@ public override string LocalName { XmlReaderSettings settings = new XmlReaderSettings { -#if NET35 - ProhibitDtd = true, -#else DtdProcessing = DtdProcessing.Prohibit, -#endif }; using (XmlReader xmlReader = XmlConvertingReaderFactory.Create(stringReader, Features.GetNamespaceResolver(), settings)) diff --git a/src/DocumentFormat.OpenXml.Framework/OpenXmlPartReader.cs b/src/DocumentFormat.OpenXml.Framework/OpenXmlPartReader.cs index b5f6abbba..9733edea6 100644 --- a/src/DocumentFormat.OpenXml.Framework/OpenXmlPartReader.cs +++ b/src/DocumentFormat.OpenXml.Framework/OpenXmlPartReader.cs @@ -674,11 +674,7 @@ private XmlReader CreateReader(Stream partStream, bool closeInput, long maxChara MaxCharactersInDocument = maxCharactersInPart, CloseInput = closeInput, IgnoreWhitespace = ignoreWhitespace, -#if NET35 - ProhibitDtd = true, -#else DtdProcessing = DtdProcessing.Prohibit, -#endif }; var xmlReader = XmlConvertingReaderFactory.Create(partStream, _resolver, settings); diff --git a/src/DocumentFormat.OpenXml.Framework/OpenXmlPartRootElement.cs b/src/DocumentFormat.OpenXml.Framework/OpenXmlPartRootElement.cs index 49489115e..8fa3c4d5c 100644 --- a/src/DocumentFormat.OpenXml.Framework/OpenXmlPartRootElement.cs +++ b/src/DocumentFormat.OpenXml.Framework/OpenXmlPartRootElement.cs @@ -121,11 +121,7 @@ internal bool LoadFromPart(OpenXmlPart openXmlPart, Stream partStream, bool stri // set MaxCharactersInDocument to limit the part size on loading DOM. context.XmlReaderSettings.MaxCharactersInDocument = openXmlPart.MaxCharactersInPart; -#if NET35 - context.XmlReaderSettings.ProhibitDtd = true; // set true explicitly for security fix -#else context.XmlReaderSettings.DtdProcessing = DtdProcessing.Prohibit; // set to prohibit explicitly for security fix -#endif using (var xmlReader = XmlConvertingReaderFactory.Create(partStream, Features.GetNamespaceResolver(), context.XmlReaderSettings, strictRelationshipFound)) { diff --git a/src/DocumentFormat.OpenXml.Framework/Packaging/FlatOpcExtensions.cs b/src/DocumentFormat.OpenXml.Framework/Packaging/FlatOpcExtensions.cs index f2d91faf0..d32b9e043 100644 --- a/src/DocumentFormat.OpenXml.Framework/Packaging/FlatOpcExtensions.cs +++ b/src/DocumentFormat.OpenXml.Framework/Packaging/FlatOpcExtensions.cs @@ -90,14 +90,10 @@ public static XDocument ToFlatOpcDocument(this OpenXmlPackage openXmlPackage) /// The corresponding . private static XElement GetContentsAsXml(IPackagePart part, HashSet altChunkPartUris) { -#if NET35 - var settings = default(XmlReaderSettings); -#else var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, }; -#endif if (part.ContentType.EndsWith("xml", StringComparison.Ordinal) && !altChunkPartUris.Contains(part.Uri)) diff --git a/src/DocumentFormat.OpenXml.Framework/System/EnumHelper.cs b/src/DocumentFormat.OpenXml.Framework/System/EnumHelper.cs index 45d9e44cd..e6b24199c 100644 --- a/src/DocumentFormat.OpenXml.Framework/System/EnumHelper.cs +++ b/src/DocumentFormat.OpenXml.Framework/System/EnumHelper.cs @@ -7,25 +7,8 @@ namespace DocumentFormat.OpenXml { internal static class EnumHelper { -#if NET35 - public static bool TryParse(string? value, out TEnum result) - where TEnum : struct - { - try - { - result = (TEnum)Enum.Parse(typeof(TEnum), value); - return true; - } - catch (Exception) - { - result = default; - return false; - } - } -#else public static bool TryParse(string? value, out TEnum result) where TEnum : struct => Enum.TryParse(value, out result); -#endif } } diff --git a/src/DocumentFormat.OpenXml.Framework/Validation/OpenXmlValidator.cs b/src/DocumentFormat.OpenXml.Framework/Validation/OpenXmlValidator.cs index 0142b0b04..c2e65816f 100644 --- a/src/DocumentFormat.OpenXml.Framework/Validation/OpenXmlValidator.cs +++ b/src/DocumentFormat.OpenXml.Framework/Validation/OpenXmlValidator.cs @@ -84,14 +84,8 @@ public IEnumerable Validate(OpenXmlPackage openXmlPackage) /// Cancellation token /// A set of validation errors. /// Thrown when the parameter is null. -#if !NET35 - public -#else - private -#endif - IEnumerable Validate(OpenXmlPackage openXmlPackage, CancellationToken token = default) + public IEnumerable Validate(OpenXmlPackage openXmlPackage, CancellationToken token = default) { - // Note: This is private on .NET 3.5 as CancellationToken on that platform is not available. if (openXmlPackage is null) { throw new ArgumentNullException(nameof(openXmlPackage)); @@ -129,14 +123,8 @@ public IEnumerable Validate(OpenXmlPart openXmlPart) /// A set of validation errors. /// Thrown when the parameter is null. /// Throw when the specified part is not a defined part in the specified version. -#if !NET35 - public -#else - private -#endif - IEnumerable Validate(OpenXmlPart openXmlPart, CancellationToken token = default) + public IEnumerable Validate(OpenXmlPart openXmlPart, CancellationToken token = default) { - // Note: This is private on .NET 3.5 as CancellationToken on that platform is not available. if (openXmlPart is null) { throw new ArgumentNullException(nameof(openXmlPart)); @@ -179,14 +167,8 @@ public IEnumerable Validate(OpenXmlElement openXmlElement) /// Thrown when the parameter is null. /// Thrown when the is type of , , , or . /// Thrown when the is not defined in the specified . -#if !NET35 - public -#else - private -#endif - IEnumerable Validate(OpenXmlElement openXmlElement, CancellationToken token = default) + public IEnumerable Validate(OpenXmlElement openXmlElement, CancellationToken token = default) { - // Note: This is private on .NET 3.5 as CancellationToken on that platform is not available. if (openXmlElement is null) { throw new ArgumentNullException(nameof(openXmlElement)); diff --git a/src/DocumentFormat.OpenXml.Framework/Validation/Schema/ExpectedChildren.cs b/src/DocumentFormat.OpenXml.Framework/Validation/Schema/ExpectedChildren.cs index 0c130e969..38803f78b 100644 --- a/src/DocumentFormat.OpenXml.Framework/Validation/Schema/ExpectedChildren.cs +++ b/src/DocumentFormat.OpenXml.Framework/Validation/Schema/ExpectedChildren.cs @@ -139,11 +139,7 @@ internal string GetExpectedChildrenMessage(OpenXmlElement parent) } } -#if NET35 - var final = childrenNames.ToArray(); -#else var final = childrenNames; -#endif return SR.Format(ValidationResources.Fmt_ListOfPossibleElements, string.Join(ValidationResources.Fmt_ElementNameSeparator, final)); } diff --git a/src/DocumentFormat.OpenXml.Framework/XmlConvertingReader.cs b/src/DocumentFormat.OpenXml.Framework/XmlConvertingReader.cs index 76b3bd350..f7d97dbab 100644 --- a/src/DocumentFormat.OpenXml.Framework/XmlConvertingReader.cs +++ b/src/DocumentFormat.OpenXml.Framework/XmlConvertingReader.cs @@ -43,11 +43,7 @@ protected override void Dispose(bool disposing) { base.Dispose(disposing); -#if NET35 || NET40 - ((IDisposable)BaseReader).Dispose(); -#else BaseReader.Dispose(); -#endif } /// diff --git a/src/DocumentFormat.OpenXml.Framework/XmlDOMTextWriter.cs b/src/DocumentFormat.OpenXml.Framework/XmlDOMTextWriter.cs index 9970ac62a..dbdf76746 100644 --- a/src/DocumentFormat.OpenXml.Framework/XmlDOMTextWriter.cs +++ b/src/DocumentFormat.OpenXml.Framework/XmlDOMTextWriter.cs @@ -147,11 +147,7 @@ protected override void Dispose(bool disposing) if (disposing) { -#if NET35 || NET40 - ((IDisposable)_writer).Dispose(); -#else _writer.Dispose(); -#endif } } } diff --git a/src/common/FrameworkShims.targets b/src/common/FrameworkShims.targets index f846188a7..8099240fb 100644 --- a/src/common/FrameworkShims.targets +++ b/src/common/FrameworkShims.targets @@ -11,36 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/System/Collections/Concurrent/ConcurrentDictionary.cs b/src/common/System/Collections/Concurrent/ConcurrentDictionary.cs deleted file mode 100644 index 0b1ad840e..000000000 --- a/src/common/System/Collections/Concurrent/ConcurrentDictionary.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Generic; - -#pragma warning disable CA1812 - -namespace System.Collections.Concurrent -{ - internal sealed class ConcurrentDictionary - { - private readonly Dictionary _dictionary; - - public ConcurrentDictionary() - { - _dictionary = new Dictionary(); - } - - public ConcurrentDictionary(IEnumerable> values) - { - _dictionary = new Dictionary(); - - foreach (var value in values) - { - _dictionary.Add(value.Key, value.Value); - } - } - - public TValue GetOrAdd(TKey type, Func create) - { - lock (_dictionary) - { - if (!_dictionary.TryGetValue(type, out var result)) - { - result = create(type); - _dictionary[type] = result; - } - - return result; - } - } - - public bool TryGetValue(TKey key, out TValue value) - { - lock (_dictionary) - { - return _dictionary.TryGetValue(key, out value); - } - } - - public void TryAdd(TKey key, TValue value) - { - lock (_dictionary) - { - if (!_dictionary.ContainsKey(key)) - { - _dictionary.Add(key, value); - } - } - } - } -} diff --git a/src/common/System/Collections/Generic/IReadOnlyCollection.cs b/src/common/System/Collections/Generic/IReadOnlyCollection.cs deleted file mode 100644 index f039354f7..000000000 --- a/src/common/System/Collections/Generic/IReadOnlyCollection.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Generic; - -namespace DocumentFormat.OpenXml -{ - internal interface IReadOnlyCollection : IEnumerable - { - int Count { get; } - } -} diff --git a/src/common/System/Collections/Generic/IReadOnlyDictionary.cs b/src/common/System/Collections/Generic/IReadOnlyDictionary.cs deleted file mode 100644 index 0b0da2772..000000000 --- a/src/common/System/Collections/Generic/IReadOnlyDictionary.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Collections.Generic; - -namespace DocumentFormat.OpenXml -{ - internal interface IReadOnlyDictionary : IReadOnlyCollection> - { - TValue this[TKey key] { get; } - - IEnumerable Keys { get; } - - IEnumerable Values { get; } - - bool ContainsKey(TKey key); - - bool TryGetValue(TKey key, out TValue value); - } -} diff --git a/src/common/System/FormattableString.cs b/src/common/System/FormattableString.cs deleted file mode 100644 index 98b3f4616..000000000 --- a/src/common/System/FormattableString.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.Globalization; - -namespace System -{ - internal sealed class FormattableString : IFormattable - { - private readonly string _format; - private readonly object[] _arguments; - - public FormattableString(string format, object[] arguments) - { - _format = format; - _arguments = arguments; - } - - string IFormattable.ToString(string format, IFormatProvider formatProvider) => ToString(formatProvider); - - public string ToString(IFormatProvider formatProvider) => string.Format(formatProvider, _format, _arguments); - - public static string Invariant(FormattableString formattable) - { - if (formattable == null) - { - throw new ArgumentNullException(nameof(formattable)); - } - - return formattable.ToString(CultureInfo.InvariantCulture); - } - - public override string ToString() => ToString(CultureInfo.CurrentCulture); - } -} diff --git a/src/common/System/IO/StreamCopyExtensions.cs b/src/common/System/IO/StreamCopyExtensions.cs deleted file mode 100644 index c1f1c0695..000000000 --- a/src/common/System/IO/StreamCopyExtensions.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.IO; - -namespace DocumentFormat.OpenXml -{ - internal static class StreamCopyExtensions - { - public static void CopyTo(this Stream source, Stream destination) - { - const int BufferSize = 4096; - - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - - if (destination == null) - { - throw new ArgumentNullException(nameof(destination)); - } - - var buffer = new byte[BufferSize]; - int bytesRead; - - while ((bytesRead = source.Read(buffer, 0, BufferSize)) > 0) - { - destination.Write(buffer, 0, bytesRead); - } - } - } -} diff --git a/src/common/System/Lazy{T}.cs b/src/common/System/Lazy{T}.cs deleted file mode 100644 index e0b204ebb..000000000 --- a/src/common/System/Lazy{T}.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -#pragma warning disable CA1812 - -using System; - -namespace DocumentFormat.OpenXml -{ - /// - /// An implementation of Lazy{T} that is supported on .NET 3.5 and is always thread-safe. - /// - /// Type to create. - internal sealed class Lazy - { - private readonly object _sync = new object(); - - private T? _value; - private Func? _factory; - private bool _isValueCreated; - - public Lazy(Func factory, bool isThreadSafe) - { - _factory = factory; - } - - public Lazy(Func factory) - { - _factory = factory; - } - - public bool IsValueCreated - { - get - { - lock (_sync) - { - return _isValueCreated; - } - } - } - - public T Value - { - get - { - if (!_isValueCreated) - { - lock (_sync) - { - if (!_isValueCreated && _factory is not null) - { - _value = _factory(); - _isValueCreated = true; - _factory = null; - } - } - } - - return _value!; - } - } - } -} diff --git a/src/common/System/Reflection/TypeExtensions.cs b/src/common/System/Reflection/TypeExtensions.cs deleted file mode 100644 index f0cd686ee..000000000 --- a/src/common/System/Reflection/TypeExtensions.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace DocumentFormat.OpenXml -{ - /// - /// TypeInfo is used in the code base as .NET Standard requires it. However, .NET 4.0 and .NET 3.5 do not have this or other - /// convience methods introduced in .NET 4.5 that are used. This provides similar functionality. - /// - internal static class TypeExtensions - { - public static Type GetTypeInfo(this Type type) => type; - - public static Attribute GetCustomAttribute(this MemberInfo element, Type attributeType) - { - return Attribute.GetCustomAttribute(element, attributeType); - } - - public static T GetCustomAttribute(this MemberInfo element) - where T : Attribute - { - return (T)GetCustomAttribute(element, typeof(T)); - } - - public static IEnumerable GetCustomAttributes(this MemberInfo element, Type attributeType) - { - return Attribute.GetCustomAttributes(element, attributeType); - } - - public static IEnumerable GetCustomAttributes(this MemberInfo element) - where T : Attribute - { - return (IEnumerable)GetCustomAttributes(element, typeof(T)); - } - - public static IEnumerable GetCustomAttributes(this MemberInfo element, Type attributeType, bool inherit) - { - return Attribute.GetCustomAttributes(element, attributeType, inherit); - } - - public static IEnumerable GetCustomAttributes(this MemberInfo element, bool inherit) - where T : Attribute - { - return (IEnumerable)GetCustomAttributes(element, typeof(T), inherit); - } - - public static FieldInfo GetDeclaredField(this Type type, string name) - { - return type.GetField(name); - } - - public static IEnumerable GetRuntimeProperties(this Type type) - { - return type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); - } - - public static PropertyInfo? GetRuntimeProperty(this Type type, string name) - { - return type.GetProperty(name); - } - -#if NET35 || NET40 - public static object? GetValue(this PropertyInfo property, object? obj) - { - return property.GetValue(obj, index: null); - } -#endif - } -} diff --git a/src/common/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs b/src/common/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs deleted file mode 100644 index 0147a00f5..000000000 --- a/src/common/System/Runtime/CompilerServices/CallerMemberNameAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace System.Runtime.CompilerServices -{ - [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] - internal sealed class CallerMemberNameAttribute : Attribute - { - public CallerMemberNameAttribute() - { - } - } -} diff --git a/src/common/System/Runtime/CompilerServices/FormattableStringFactory.cs b/src/common/System/Runtime/CompilerServices/FormattableStringFactory.cs deleted file mode 100644 index 9e7736163..000000000 --- a/src/common/System/Runtime/CompilerServices/FormattableStringFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace System.Runtime.CompilerServices -{ - internal static class FormattableStringFactory - { - public static FormattableString Create(string format, params object[] arguments) - { - return new FormattableString(format, arguments); - } - } -} diff --git a/src/common/System/Threading/CancellationToken.cs b/src/common/System/Threading/CancellationToken.cs deleted file mode 100644 index 9d440730f..000000000 --- a/src/common/System/Threading/CancellationToken.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -#pragma warning disable CA1822 - -namespace System.Threading -{ - internal readonly struct CancellationToken - { - public void ThrowIfCancellationRequested() - { - } - } -} diff --git a/src/common/System/Xml/Linq/XDocumentExtensions.cs b/src/common/System/Xml/Linq/XDocumentExtensions.cs deleted file mode 100644 index ce7cb2e56..000000000 --- a/src/common/System/Xml/Linq/XDocumentExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System.IO; - -namespace System.Xml.Linq -{ - internal static class XDocumentExtensions - { - public static void Save(this XDocument doc, Stream stream) - { - using var writer = new StreamWriter(stream); - - doc.Save(writer); - } - } -} diff --git a/test/DocumentFormat.OpenXml.Tests/OpenXmlElementContextTests.cs b/test/DocumentFormat.OpenXml.Tests/OpenXmlElementContextTests.cs index 0785a0258..2bce7bfee 100644 --- a/test/DocumentFormat.OpenXml.Tests/OpenXmlElementContextTests.cs +++ b/test/DocumentFormat.OpenXml.Tests/OpenXmlElementContextTests.cs @@ -39,11 +39,7 @@ public void SetMarkupCompatibility() [Theory] public void XmlReaderSettingsSet(XmlReaderSettings settings) { -#if NET35 - Assert.True(xmlReader.ProhibitDtd); -#else Assert.Equal(DtdProcessing.Prohibit, settings.DtdProcessing); -#endif Assert.False(settings.IgnoreWhitespace); Assert.IsType(settings.NameTable); diff --git a/test/DocumentFormat.OpenXml.Tests/ofapiTest/ValidatorCancellationExtensions.cs b/test/DocumentFormat.OpenXml.Tests/ofapiTest/ValidatorCancellationExtensions.cs deleted file mode 100644 index f9f935930..000000000 --- a/test/DocumentFormat.OpenXml.Tests/ofapiTest/ValidatorCancellationExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -#if FEATURE_NO_VALIDATOR_CANCELLATIONTOKEN - -using DocumentFormat.OpenXml.Packaging; -using DocumentFormat.OpenXml.Validation; -using System.Collections.Generic; - -namespace DocumentFormat.OpenXml.Tests; - -/// -/// Used for tests that cross compile and need to pass in a cancellation token. Since this is shadowed currently in the .NET 3.5 builds, -/// we take the token as an object since we don't need to do anything besides compile. -/// -internal static class ValidatorCancellationExtensions -{ - internal static IEnumerable Validate(this OpenXmlValidator validator, OpenXmlPackage package, object token) - => validator.Validate(package); - - internal static IEnumerable Validate(this OpenXmlValidator validator, OpenXmlElement element, object token) - => validator.Validate(element); - - internal static IEnumerable Validate(this OpenXmlValidator validator, OpenXmlPart part, object token) - => validator.Validate(part); -} - -#endif