Skip to content

Commit 1c1f245

Browse files
committed
The WinGetInfoEntry class and all derived classes now implement the IEquatable<T> and ICloneable interfaces
1 parent 02afdc0 commit 1c1f245

6 files changed

Lines changed: 155 additions & 15 deletions

File tree

‎src/WGet.NET/Abstractions/WinGetInfoEntry.cs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
// Created by basicx-StrgV //
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
5+
using System;
6+
57
namespace WGetNET.Abstractions
68
{
79
/// <summary>
810
/// Represents a basic winget info entry.
911
/// </summary>
10-
public abstract class WinGetInfoEntry : IWinGetObject
12+
/// <typeparam name="T">
13+
/// The type of the derived class.
14+
/// </typeparam>
15+
public abstract class WinGetInfoEntry<T> : IWinGetObject, IEquatable<T>, ICloneable where T : WinGetInfoEntry<T>
1116
{
1217
/// <summary>
1318
/// Gets the name of the info entry.
@@ -62,7 +67,7 @@ public virtual bool IsEmpty
6267
private protected readonly bool _hasShortenedContent;
6368

6469
/// <summary>
65-
/// Initializes a new instance of the <see cref="WinGetInfoEntry"/> class.
70+
/// Initializes a new instance of the <see cref="WGetNET.Abstractions.WinGetInfoEntry{T}"/> class.
6671
/// </summary>
6772
/// <param name="entryName">The name of the info entry.</param>
6873
/// <param name="rawContent">The content of the info entry.</param>
@@ -79,5 +84,11 @@ public override string ToString()
7984
{
8085
return _entryName;
8186
}
87+
88+
/// <inheritdoc/>
89+
public abstract bool Equals(T? other);
90+
91+
/// <inheritdoc/>
92+
public abstract object Clone();
8293
}
8394
}

‎src/WGet.NET/Abstractions/WinGetObjectBuilder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace WGetNET.Abstractions
88
/// Base class for internal builders.
99
/// </summary>
1010
/// <typeparam name="T">
11-
/// Type of the class the builder creates an instance of.
11+
/// The type of the class the builder creates an instance of.
1212
/// The class needs to inherit <see cref="WGetNET.IWinGetObject"/>.
1313
/// </typeparam>
1414
internal abstract class WinGetObjectBuilder<T> where T : IWinGetObject?

‎src/WGet.NET/Data/WinGetAdminOption.cs‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace WGetNET
99
/// <summary>
1010
/// Represents a winget admin settings entry.
1111
/// </summary>
12-
public sealed class WinGetAdminOption : WinGetInfoEntry
12+
public sealed class WinGetAdminOption : WinGetInfoEntry<WinGetAdminOption>
1313
{
1414
/// <summary>
1515
/// Gets if the admin option is enabled.
@@ -35,5 +35,39 @@ internal WinGetAdminOption(string entryName, string rawContent, bool hasShortene
3535
{
3636
_isEnabled = isEnabled;
3737
}
38+
39+
/// <inheritdoc/>
40+
public override bool Equals(WinGetAdminOption? other)
41+
{
42+
if (other == null)
43+
{
44+
return false;
45+
}
46+
47+
if (ReferenceEquals(this, other))
48+
{
49+
return true;
50+
}
51+
52+
if (_entryName.Equals(other.EntryName) && _rawContent.Equals(other.RawContent) &&
53+
_hasShortenedContent.Equals(other.HasShortenedContent) &&
54+
_isEnabled.Equals(other.IsEnabled))
55+
{
56+
return true;
57+
}
58+
59+
return false;
60+
}
61+
62+
/// <inheritdoc/>
63+
public override object Clone()
64+
{
65+
return new WinGetAdminOption(
66+
_entryName,
67+
_rawContent,
68+
_hasShortenedContent,
69+
_isEnabled
70+
);
71+
}
3872
}
3973
}

‎src/WGet.NET/Data/WinGetDirectory.cs‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace WGetNET
1010
/// <summary>
1111
/// Represents a winget directory in the info set.
1212
/// </summary>
13-
public sealed class WinGetDirectory : WinGetInfoEntry
13+
public sealed class WinGetDirectory : WinGetInfoEntry<WinGetDirectory>
1414
{
1515
/// <summary>
1616
/// Gets a value indicating whether the directory exists.
@@ -69,5 +69,39 @@ internal WinGetDirectory(string entryName, string rawContent, bool hasShortenedC
6969
{
7070
_directoryInfo = directoryInfo;
7171
}
72+
73+
/// <inheritdoc/>
74+
public override bool Equals(WinGetDirectory? other)
75+
{
76+
if (other == null)
77+
{
78+
return false;
79+
}
80+
81+
if (ReferenceEquals(this, other))
82+
{
83+
return true;
84+
}
85+
86+
if (_entryName.Equals(other.EntryName) && _rawContent.Equals(other.RawContent) &&
87+
_hasShortenedContent.Equals(other.HasShortenedContent) &&
88+
_directoryInfo.Equals(other.Info))
89+
{
90+
return true;
91+
}
92+
93+
return false;
94+
}
95+
96+
/// <inheritdoc/>
97+
public override object Clone()
98+
{
99+
return new WinGetDirectory(
100+
_entryName,
101+
_rawContent,
102+
_hasShortenedContent,
103+
_directoryInfo
104+
);
105+
}
72106
}
73107
}

‎src/WGet.NET/Data/WinGetLink.cs‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace WGetNET
1010
/// <summary>
1111
/// Represents a winget link in the info set.
1212
/// </summary>
13-
public sealed class WinGetLink : WinGetInfoEntry
13+
public sealed class WinGetLink : WinGetInfoEntry<WinGetLink>
1414
{
1515
/// <summary>
1616
/// Gets the url.
@@ -36,5 +36,39 @@ internal WinGetLink(string entryName, string rawContent, bool hasShortenedConten
3636
{
3737
_url = url;
3838
}
39+
40+
/// <inheritdoc/>
41+
public override bool Equals(WinGetLink? other)
42+
{
43+
if (other == null)
44+
{
45+
return false;
46+
}
47+
48+
if (ReferenceEquals(this, other))
49+
{
50+
return true;
51+
}
52+
53+
if (_entryName.Equals(other.EntryName) && _rawContent.Equals(other.RawContent) &&
54+
_hasShortenedContent.Equals(other.HasShortenedContent) &&
55+
_url.Equals(other.Url))
56+
{
57+
return true;
58+
}
59+
60+
return false;
61+
}
62+
63+
/// <inheritdoc/>
64+
public override object Clone()
65+
{
66+
return new WinGetLink(
67+
_entryName,
68+
_rawContent,
69+
_hasShortenedContent,
70+
_url
71+
);
72+
}
3973
}
4074
}

‎src/WGet.NET/XmlDocumentation/WGet.NET.xml‎

Lines changed: 36 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)