1
1
// Copyright (c) Microsoft. All rights reserved.
2
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
- #nullable disable
5
-
6
4
using System ;
7
5
6
+ #if ! NET5_0
7
+ using DocumentFormat . OpenXml . Framework ;
8
+ #endif
9
+
8
10
namespace DocumentFormat . OpenXml . Packaging
9
11
{
10
12
/// <summary>
11
13
/// Represents a (RelationshipId, OpenXmlPart) pair.
12
14
/// </summary>
13
- public class IdPartPair
15
+ public class IdPartPair : IEquatable < IdPartPair >
14
16
{
15
- private string _id ;
16
- private OpenXmlPart _part ;
17
-
18
17
/// <summary>
19
18
/// Gets or sets the relationship ID in the pair.
20
19
/// </summary>
21
20
public string RelationshipId
22
21
{
23
- get { return _id ; }
24
- set { _id = value ; }
22
+ get ;
23
+ [ Obsolete ( "This object will be made immutable in a future release. Please use a new instance." ) ]
24
+ set ;
25
25
}
26
26
27
27
/// <summary>
28
28
/// Gets or sets the OpenXmlPart in the pair.
29
29
/// </summary>
30
30
public OpenXmlPart OpenXmlPart
31
31
{
32
- get { return _part ; }
33
- set { _part = value ; }
32
+ get ;
33
+ [ Obsolete ( "This object will be made immutable in a future release. Please use a new instance." ) ]
34
+ set ;
34
35
}
35
36
36
37
/// <summary>
@@ -40,24 +41,40 @@ public OpenXmlPart OpenXmlPart
40
41
/// <param name="part">The OpenXmlPart.</param>
41
42
public IdPartPair ( string id , OpenXmlPart part )
42
43
{
44
+ #pragma warning disable CS0618 // Type or member is obsolete
43
45
RelationshipId = id ;
44
46
OpenXmlPart = part ;
47
+ #pragma warning restore CS0618 // Type or member is obsolete
45
48
}
46
49
47
- /// <summary>
48
- /// Determines whether this instance and another specified IdPartPair object have the same value.
49
- /// </summary>
50
- /// <param name="value">An IdPartPair.</param>
51
- /// <returns>True if the value of the value parameter is the same as this instance; otherwise, false.</returns>
52
- public bool Equals ( IdPartPair value )
50
+ /// <inheritdoc/>
51
+ public override bool Equals ( object ? obj ) => obj is IdPartPair other && Equals ( other ) ;
52
+
53
+ /// <inheritdoc/>
54
+ public override int GetHashCode ( )
55
+ {
56
+ var code = new HashCode ( ) ;
57
+
58
+ code . Add ( RelationshipId , StringComparer . Ordinal ) ;
59
+
60
+ return code . ToHashCode ( ) ;
61
+ }
62
+
63
+ /// <inheritdoc/>
64
+ public bool Equals ( IdPartPair ? value )
53
65
{
54
66
//Check for null
55
67
if ( value is null )
56
68
{
57
69
return false ;
58
70
}
59
71
60
- return string . Equals ( _id , value . _id , StringComparison . Ordinal ) && ( _part == value . _part ) ;
72
+ if ( ReferenceEquals ( this , value ) )
73
+ {
74
+ return true ;
75
+ }
76
+
77
+ return string . Equals ( RelationshipId , value . RelationshipId , StringComparison . Ordinal ) && ( OpenXmlPart == value . OpenXmlPart ) ;
61
78
}
62
79
}
63
80
}
0 commit comments