Skip to content

Commit 45159c1

Browse files
committed
Added the SamePackage(...) method to the WinGetPackage class for comparing of to packages
1 parent c40a2d6 commit 45159c1

4 files changed

Lines changed: 112 additions & 189 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,39 @@ public static WinGetPackage Create(string name, string id, Version version, Vers
301301
return builder.GetInstance();
302302
}
303303

304+
/// <summary>
305+
/// Checks if two packages are the same and optionally if they also have the same version.
306+
/// </summary>
307+
/// <param name="other">
308+
/// The <see cref="WGetNET.WinGetPackage"/> to compare with.
309+
/// </param>
310+
/// <param name="sameVersion">
311+
/// Set to <see langword="true"/> to also check for the same version.
312+
/// </param>
313+
/// <returns>
314+
/// <see langword="true"/> if both packages are the same and <see langword="false"/> if not.
315+
/// </returns>
316+
public bool SamePackage(WinGetPackage other, bool sameVersion = false)
317+
{
318+
if (other == null)
319+
{
320+
return false;
321+
}
322+
323+
if (ReferenceEquals(this, other))
324+
{
325+
return true;
326+
}
327+
328+
if (_id.Equals(other.Id) && _sourceName.Equals(other.SourceName) &&
329+
(!sameVersion || (_versionString.Equals(other.VersionString) && _version.Equals(other.Version))))
330+
{
331+
return true;
332+
}
333+
334+
return false;
335+
}
336+
304337
/// <inheritdoc/>
305338
public virtual object Clone()
306339
{

0 commit comments

Comments
 (0)