Skip to content

Commit 0d46586

Browse files
committed
Improve code quality
1 parent 5b8e7ce commit 0d46586

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/PatternColor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ public class PatternColor : ExtendedColor
1414
/// Creates a color representing a pattern.
1515
/// </summary>
1616
/// <param name="painter">the actual pattern</param>
17-
public PatternColor(PdfPatternPainter painter) : base(TYPE_PATTERN, .5f, .5f, .5f) => _painter = painter;
17+
public PatternColor(PdfPatternPainter painter) : base(TYPE_PATTERN, red: .5f, green: .5f, blue: .5f)
18+
=> _painter = painter;
1819

1920
/// <summary>
2021
/// Gets the pattern.
2122
/// </summary>
2223
/// <returns>the pattern</returns>
2324
public PdfPatternPainter Painter => _painter;
2425

25-
public override bool Equals(object obj) => this == obj;
26+
public override bool Equals(object obj) => obj is PatternColor color && color.Painter.Equals(Painter);
2627

2728
public override int GetHashCode() => _painter.GetHashCode();
2829
}

src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/PdfName.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,19 +3460,7 @@ public int CompareTo(object obj)
34603460
/// <param name="obj">the reference object with which to compare.</param>
34613461
/// <returns> true if this object is the same as the obj</returns>
34623462
public override bool Equals(object obj)
3463-
{
3464-
if (this == obj)
3465-
{
3466-
return true;
3467-
}
3468-
3469-
if (obj is PdfName)
3470-
{
3471-
return CompareTo(obj) == 0;
3472-
}
3473-
3474-
return false;
3475-
}
3463+
=> !ReferenceEquals(objA: null, obj) && (ReferenceEquals(this, obj) || (obj is PdfName && CompareTo(obj) == 0));
34763464

34773465
/// <summary>
34783466
/// Returns a hash code value for the object. This method is

src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/PdfPKCS7.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ public byte[] GetEncodedPkcs7(byte[] secondDigest, DateTime signingTime, ITsaCli
11371137
// }
11381138

11391139
// Only allow one signerInfo
1140-
body.Add(new DerSet(new DerSequence(signerinfo)));
1140+
body.Add(DerSet.FromElement(new DerSequence(signerinfo)));
11411141

11421142
// Now we have the body, wrap it in it's PKCS7Signed shell
11431143
// and return it
@@ -1391,7 +1391,7 @@ private static Asn1EncodableVector buildUnauthenticatedAttributes(byte[] timeSta
13911391
var v = new Asn1EncodableVector();
13921392
v.Add(new DerObjectIdentifier(idTimeStampToken)); // id-aa-timeStampToken
13931393
var seq = (Asn1Sequence)tempstream.ReadObject();
1394-
v.Add(new DerSet(seq));
1394+
v.Add(DerSet.FromElement(seq));
13951395

13961396
unauthAttributes.Add(new DerSequence(v));
13971397

@@ -1524,7 +1524,7 @@ private static DerSet getAuthenticatedAttributeSet(byte[] secondDigest, DateTime
15241524
v3.Add(den);
15251525
v3.Add(new DerTaggedObject(isExplicit: true, tagNo: 0, new DerSequence(v2)));
15261526
vo1.Add(new DerSequence(v3));
1527-
v.Add(new DerSet(new DerSequence(new DerTaggedObject(isExplicit: true, tagNo: 1, new DerSequence(vo1)))));
1527+
v.Add(DerSet.FromElement(new DerSequence(new DerTaggedObject(isExplicit: true, tagNo: 1, new DerSequence(vo1)))));
15281528
attribute.Add(new DerSequence(v));
15291529
}
15301530

src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/ShadingColor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ namespace iTextSharp.text.pdf;
66
/// </summary>
77
public class ShadingColor : ExtendedColor
88
{
9-
public ShadingColor(PdfShadingPattern shadingPattern) : base(TYPE_SHADING, .5f, .5f, .5f) =>
10-
PdfShadingPattern = shadingPattern;
9+
public ShadingColor(PdfShadingPattern shadingPattern) : base(TYPE_SHADING, red: .5f, green: .5f, blue: .5f)
10+
=> PdfShadingPattern = shadingPattern;
1111

1212
public PdfShadingPattern PdfShadingPattern { get; }
1313

14-
public override bool Equals(object obj) => this == obj;
14+
public override bool Equals(object obj)
15+
=> obj is ShadingColor color && color.PdfShadingPattern.Equals(PdfShadingPattern);
1516

1617
public override int GetHashCode() => PdfShadingPattern.GetHashCode();
1718
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
using System.util;
2+
13
namespace iTextSharp.text.pdf;
24

35
/// <summary>
46
/// @author psoares
57
/// </summary>
68
public class SpotColor : ExtendedColor
79
{
8-
public SpotColor(PdfSpotColor spot, float tint) :
9-
base(TYPE_SEPARATION,
10-
((spot?.AlternativeCs.R ?? throw new ArgumentNullException(nameof(spot))) / 255f - 1f) * tint + 1,
11-
(spot.AlternativeCs.G / 255f - 1f) * tint + 1,
12-
(spot.AlternativeCs.B / 255f - 1f) * tint + 1)
10+
public SpotColor(PdfSpotColor spot, float tint) : base(TYPE_SEPARATION,
11+
((spot?.AlternativeCs.R ?? throw new ArgumentNullException(nameof(spot))) / 255f - 1f) * tint + 1,
12+
(spot.AlternativeCs.G / 255f - 1f) * tint + 1, (spot.AlternativeCs.B / 255f - 1f) * tint + 1)
1313
{
1414
PdfSpotColor = spot;
1515
Tint = tint;
@@ -23,7 +23,8 @@ public SpotColor(PdfSpotColor spot, float tint) :
2323

2424
public float Tint { get; }
2525

26-
public override bool Equals(object obj) => this == obj;
26+
public override bool Equals(object obj)
27+
=> obj is SpotColor color && color.PdfSpotColor.Equals(PdfSpotColor) && color.Tint.ApproxEquals(Tint);
2728

2829
public override int GetHashCode() => PdfSpotColor.GetHashCode() ^ Tint.GetHashCode();
2930
}

0 commit comments

Comments
 (0)