Skip to content

Commit

Permalink
Remove a number of obsolete APIs (#1316)
Browse files Browse the repository at this point in the history
* Remove a number of obsolete APIs:

- Removed setters from IdPartPair and converted to readonly struct
- Removed shims for obsolete typed APIs
- Removed obsolete APIs from XmlPath
  • Loading branch information
twsouthwick authored Jan 25, 2023
1 parent 2af7c7a commit 4260711
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 370 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- .NET Standard 1.3 is no longer a supported platform. .NET Standard 2.0 is the lowest .NET Standard supported.

### Breaking change
- IdPartPair is now a readonly struct rather than a class
- IDisposableFeature is now a part of the framework package and is available by default on a package. Extension methods to manage this feature have been removed as it no longer needs to be opted into. It now registers all disposable actions to be done at the package level instead of adding support at the part level.
- OpenXmlPackage.CanSave is now an instance method
- Core infrastructure is now contained in a new package DocumentFormat.OpenXml.Framework. Typed classes are still in DocumentFormat.OpenXml. This means that you may reference DocumentFormat.OpenXml and still compile the same types, but if you want a smaller package, you may rely on just the framework package.
Expand All @@ -22,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Removed unused `ChildElementInfoAttribute`
- Removed `OpenXmlSimpleType.TextValue`. This property was never meant to be used externally
- Removed obsolete validation logic from v1 of the SDK
- Removed obsoleted methods from 2.x
- Removed mutable properties on OpenXmlAttribute and marked as `readonly`

## [2.20.0]
Expand Down
8 changes: 0 additions & 8 deletions src/DocumentFormat.OpenXml.Framework/AlternateContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ public AlternateContent(string outerXml)
/// </summary>
public static string MarkupCompatibilityNamespace => InternalQName.Namespace.Uri;

/// <summary>
/// Gets a value that represents the markup compatibility
/// namespace ID.
/// </summary>
[Obsolete("NamespaceId will be removed in later releases.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static byte MarkupCompatibilityNamespaceId => 0;

/// <summary>
/// Gets a value that represents the tag name of the
/// AlternateContent element.
Expand Down
26 changes: 0 additions & 26 deletions src/DocumentFormat.OpenXml.Framework/AppendOption.cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlCompositeElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,6 @@ protected OpenXmlCompositeElement(string outerXml)
{
}

/// <summary>
/// Initializes a new instance of the OpenXmlCompositeElement class using the supplied collection of elements.
/// </summary>
/// <param name="childrenElements">A collection of elements.</param>
[Obsolete(UseGenericVersion)]
protected OpenXmlCompositeElement(IEnumerable childrenElements)
: this()
{
if (childrenElements is null)
{
throw new ArgumentNullException(nameof(childrenElements));
}

foreach (OpenXmlElement child in childrenElements)
{
AppendChild(child);
}
}

/// <summary>
/// Initializes a new instance of the OpenXmlCompositeElement class using the supplied collection of OpenXmlElement elements.
/// </summary>
Expand Down
9 changes: 0 additions & 9 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlElementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ internal MarkupCompatibilityProcessSettings MCSettings

internal uint ACBlockLevel { get; set; }

/// <summary>
/// Initializes a new instance of the OpenXmlElementContext class.
/// </summary>
[Obsolete("This object is created internally and the public constructor will be removed at some point in the future.")]
public OpenXmlElementContext()
: this(FeatureCollection.TypedOrDefault.GetNamespaceResolver())
{
}

internal OpenXmlElementContext(IOpenXmlNamespaceResolver resolver)
{
MCContext = new MCContext(resolver);
Expand Down
9 changes: 0 additions & 9 deletions src/DocumentFormat.OpenXml.Framework/OpenXmlUnknownElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,6 @@ public OpenXmlUnknownElement(string prefix, string localName, string namespaceUr
_tagName = localName;
}

/// <summary>
/// Creates a new OpenXmlUnknownElement class by using the outer XML.
/// </summary>
/// <param name="outerXml">The outer XML of the element.</param>
/// <returns>A new OpenXmlUnknownElement class.</returns>
[Obsolete("Use extension method CreateUnknownElement off of a part container", error: true)]
public static OpenXmlUnknownElement CreateOpenXmlUnknownElement(string outerXml)
=> OpenXmlUnknownElementExtensions.CreateOpenXmlUnknownElement(FeatureCollection.TypedOrDefault, outerXml);

/// <inheritdoc/>
public override string LocalName => _tagName;

Expand Down
10 changes: 0 additions & 10 deletions src/DocumentFormat.OpenXml.Framework/Packaging/ExtendedPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ namespace DocumentFormat.OpenXml.Packaging
/// </summary>
public class ExtendedPart : OpenXmlPart
{
/// <summary>
/// Default constructor.
/// </summary>
[Obsolete("Does not set a RelationshipType")]
protected ExtendedPart()
: base()
{
RelationshipType = null!;
}

/// <summary>
/// Initialize a new instance of ExtendedPart.
/// </summary>
Expand Down
94 changes: 37 additions & 57 deletions src/DocumentFormat.OpenXml.Framework/Packaging/IdPartPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,54 @@
using DocumentFormat.OpenXml.Framework;
#endif

namespace DocumentFormat.OpenXml.Packaging
namespace DocumentFormat.OpenXml.Packaging;

/// <summary>
/// Represents a (RelationshipId, OpenXmlPart) pair.
/// </summary>
public readonly struct IdPartPair : IEquatable<IdPartPair>
{
/// <summary>
/// Represents a (RelationshipId, OpenXmlPart) pair.
/// Initializes a new instance of the IdPartPair with the specified id and part.
/// </summary>
public class IdPartPair : IEquatable<IdPartPair>
/// <param name="id">The relationship ID.</param>
/// <param name="part">The OpenXmlPart.</param>
public IdPartPair(string id, OpenXmlPart part)
{
/// <summary>
/// Gets or sets the relationship ID in the pair.
/// </summary>
public string RelationshipId
{
get;
[Obsolete("This object will be made immutable in a future release. Please use a new instance.")]
set;
}
RelationshipId = id;
OpenXmlPart = part;
}

/// <summary>
/// Gets or sets the OpenXmlPart in the pair.
/// </summary>
public OpenXmlPart OpenXmlPart
{
get;
[Obsolete("This object will be made immutable in a future release. Please use a new instance.")]
set;
}
/// <summary>
/// Gets the relationship ID in the pair.
/// </summary>
public string RelationshipId { get; }

/// <summary>
/// Initializes a new instance of the IdPartPair with the specified id and part.
/// </summary>
/// <param name="id">The relationship ID.</param>
/// <param name="part">The OpenXmlPart.</param>
public IdPartPair(string id, OpenXmlPart part)
{
#pragma warning disable CS0618 // Type or member is obsolete
RelationshipId = id;
OpenXmlPart = part;
#pragma warning restore CS0618 // Type or member is obsolete
}
/// <summary>
/// Gets the OpenXmlPart in the pair.
/// </summary>
public OpenXmlPart OpenXmlPart { get; }

/// <inheritdoc/>
public override bool Equals(object? obj) => obj is IdPartPair other && Equals(other);
/// <inheritdoc/>
public override bool Equals(object? obj) => obj is IdPartPair other && Equals(other);

/// <inheritdoc/>
public override int GetHashCode()
{
var code = default(HashCode);
/// <inheritdoc/>
public override int GetHashCode()
{
var code = default(HashCode);

code.Add(RelationshipId, StringComparer.Ordinal);
code.Add(RelationshipId, StringComparer.Ordinal);

return code.ToHashCode();
}
return code.ToHashCode();
}

/// <inheritdoc/>
public bool Equals(IdPartPair? value)
{
// Check for null
if (value is null)
{
return false;
}
/// <inheritdoc/>
public bool Equals(IdPartPair value)
=> string.Equals(RelationshipId, value.RelationshipId, StringComparison.Ordinal) && Equals(OpenXmlPart, value.OpenXmlPart);

if (ReferenceEquals(this, value))
{
return true;
}
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public static bool operator ==(IdPartPair left, IdPartPair right) => left.Equals(right);

return string.Equals(RelationshipId, value.RelationshipId, StringComparison.Ordinal) && (OpenXmlPart == value.OpenXmlPart);
}
}
public static bool operator !=(IdPartPair left, IdPartPair right) => !(left == right);
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
Original file line number Diff line number Diff line change
Expand Up @@ -940,21 +940,6 @@ public void DeleteParts<T>(IEnumerable<T> partsToBeDeleted)
}
}

/// <summary>
/// Gets the count of all parts of type T.
/// </summary>
/// <typeparam name="T">The type of the part.</typeparam>
/// <returns>The number of parts of this type.</returns>
[Obsolete("Use GetPartsOfType<T>().Count() instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public int GetPartsCountOfType<T>()
where T : OpenXmlPart
{
ThrowIfObjectDisposed();

return GetPartsOfType<T>().Count();
}

#endregion

#region methods to operate annotation
Expand Down Expand Up @@ -1037,32 +1022,6 @@ public IEnumerable<T> GetPartsOfType<T>()
return ChildrenRelationshipParts.Parts.OfType<T>();
}

/// <summary>
/// Gets all the children parts of the specified type <typeparamref name="T"/> into <paramref name="partCollection"/> of this part.
/// </summary>
/// <typeparam name="T">Derived class from OpenXmlPart.</typeparam>
/// <param name="partCollection">The part collection to be filled in.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="partCollection"/> is null.</exception>
[Obsolete("Use GetPartsOfType<T> to manually add to a collection")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void GetPartsOfType<T>(ICollection<T> partCollection)
where T : OpenXmlPart
{
ThrowIfObjectDisposed();

if (partCollection is null)
{
throw new ArgumentNullException(nameof(partCollection));
}

partCollection.Clear();

foreach (var part in GetPartsOfType<T>())
{
partCollection.Add(part);
}
}

#region internal methods

/// <summary>
Expand Down
17 changes: 0 additions & 17 deletions src/DocumentFormat.OpenXml.Framework/XmlPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@ public XmlPath(OpenXmlElement element)
PartUri = element.GetPartUri();
XPath = TryBuildXPath(GetElements(element), out var namespaces);

#pragma warning disable CS0618 // Type or member is obsolete
if (namespaces is null)
{
Namespaces = ReadOnlyWrapper.Instance;
NamespacesDefinitions = Cached.Array<string>();
}
else
{
NamespacesDefinitions = namespaces
.GetNamespacesInScope(XmlNamespaceScope.Local)
.Select(ns => $"xmlns:{ns.Key}=\"{ns.Value}\"")
.ToArray();
Namespaces = new ReadOnlyWrapper(namespaces);
}
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
Expand All @@ -69,19 +62,9 @@ public XmlPath(OpenXmlPart part)
PartUri = part.Uri;
XPath = string.Empty;

#pragma warning disable CS0618 // Type or member is obsolete
Namespaces = ReadOnlyWrapper.Instance;
NamespacesDefinitions = Cached.Array<string>();
#pragma warning restore CS0618 // Type or member is obsolete
}

/// <summary>
/// Gets the namespace definitions used in <see cref="XPath"/>. Use <see cref="Namespaces"/> instead
/// </summary>
[Obsolete("Use the Namespaces property instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public IList<string> NamespacesDefinitions { get; }

/// <summary>
/// Gets the namespace definitions used in <see cref="XPath"/>
/// </summary>
Expand Down

This file was deleted.

Loading

0 comments on commit 4260711

Please sign in to comment.