Skip to content

Commit

Permalink
feat: implement IEquatable<T> for SteamID
Browse files Browse the repository at this point in the history
  • Loading branch information
roflmuffin committed Nov 10, 2023
1 parent d4a2ae6 commit cb6d86a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
32 changes: 31 additions & 1 deletion managed/CounterStrikeSharp.API/Modules/Entities/SteamID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace CounterStrikeSharp.API.Modules.Entities
{
public class SteamID
public class SteamID : IEquatable<SteamID>
{
const long Base = 76561197960265728;
public ulong SteamId64 { get; set; }
Expand Down Expand Up @@ -46,5 +46,35 @@ public int SteamId32
}

public override string ToString() => $"[SteamID {SteamId64}, {SteamId2}, {SteamId3}]";

public bool Equals(SteamID? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return SteamId64 == other.SteamId64;
}

public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((SteamID)obj);
}

public override int GetHashCode()
{
return SteamId64.GetHashCode();
}

public static bool operator ==(SteamID? left, SteamID? right)
{
return Equals(left, right);
}

public static bool operator !=(SteamID? left, SteamID? right)
{
return !Equals(left, right);
}
}
}
1 change: 1 addition & 0 deletions managed/TestPlugin/TestPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System;
using System.Drawing;
using System.IO;
using System.Linq;
using CounterStrikeSharp.API;
Expand Down

0 comments on commit cb6d86a

Please sign in to comment.