Improved equality checks for cache objects
This commit is contained in:
@@ -207,6 +207,8 @@ namespace Discord
|
|||||||
user.UpdateChannelPermissions(this);
|
user.UpdateChannelPermissions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is Channel && (obj as Channel).Id == Id;
|
||||||
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public override string ToString() => Name ?? Id;
|
public override string ToString() => Name ?? Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,5 +77,9 @@ namespace Discord
|
|||||||
uint mask = (uint)~(0xFF << bit);
|
uint mask = (uint)~(0xFF << bit);
|
||||||
_rawValue = (_rawValue & mask) | ((uint)value << bit);
|
_rawValue = (_rawValue & mask) | ((uint)value << bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is Color && (obj as Color)._rawValue == _rawValue;
|
||||||
|
public override int GetHashCode() => _rawValue.GetHashCode();
|
||||||
|
public override string ToString() => '#' + _rawValue.ToString("X");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ namespace Discord
|
|||||||
_client.GlobalUsers.TryRemove(Id);
|
_client.GlobalUsers.TryRemove(Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is GlobalUser && (obj as GlobalUser).Id == Id;
|
||||||
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public override string ToString() => Id;
|
public override string ToString() => Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ namespace Discord
|
|||||||
CreatedAt = model.CreatedAt.Value;
|
CreatedAt = model.CreatedAt.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is Invite && (obj as Invite).Id == Id;
|
||||||
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public override string ToString() => XkcdCode ?? Id;
|
public override string ToString() => XkcdCode ?? Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,6 +235,8 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is Message && (obj as Message).Id == Id;
|
||||||
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public override string ToString() => $"{User}: {RawText}";
|
public override string ToString() => $"{User}: {RawText}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,6 +137,9 @@ namespace Discord
|
|||||||
if (_isLocked)
|
if (_isLocked)
|
||||||
throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy.");
|
throw new InvalidOperationException("Unable to edit cached permissions directly, use Copy() to make an editable copy.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is Permissions && (obj as Permissions)._rawValue == _rawValue;
|
||||||
|
public override int GetHashCode() => _rawValue.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class DualChannelPermissions
|
public sealed class DualChannelPermissions
|
||||||
@@ -214,5 +217,10 @@ namespace Discord
|
|||||||
Deny.SetBit(pos, false);
|
Deny.SetBit(pos, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is DualChannelPermissions &&
|
||||||
|
(obj as DualChannelPermissions).Allow.Equals(Allow) &&
|
||||||
|
(obj as DualChannelPermissions).Deny.Equals(Deny);
|
||||||
|
public override int GetHashCode() => unchecked(Allow.GetHashCode() + Deny.GetHashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ namespace Discord
|
|||||||
member.UpdateServerPermissions();
|
member.UpdateServerPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is Role && (obj as Role).Id == Id;
|
||||||
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public override string ToString() => Name ?? Id;
|
public override string ToString() => Name ?? Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,6 +252,8 @@ namespace Discord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is Server && (obj as Server).Id == Id;
|
||||||
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public override string ToString() => Name ?? Id;
|
public override string ToString() => Name ?? Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,6 +370,8 @@ namespace Discord
|
|||||||
return _roles.ContainsKey(role.Id);
|
return _roles.ContainsKey(role.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj) => obj is User && (obj as User).Id == Id;
|
||||||
|
public override int GetHashCode() => Id.GetHashCode();
|
||||||
public override string ToString() => Name ?? Id;
|
public override string ToString() => Name ?? Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user