Discord.Net
Discord.Net copied to clipboard
[Feature] Embed comparison
This PR allows comparing embeds and its' child classes with each other
Changes:
Added GetHashCode(), Equals(), == operator and != operator to following classes:
EmbedEmbedFooterEmbedAuthorEmbedImageEmbedThumbnailEmbedFieldEmbedBuilderEmbedVideoEmbedFooterBuilderEmbedAuthorBuilderEmbedFieldBuilderEmbedProvider
GetHashCode shouldn't be overriden on mutable types. The hash will change every time the object is mutated, which will break code that relies on it (like dictionaries or hashsets).
Another problem I see is that an anonymous object is created every time a hash code is computed, creating unnecesary memory allocations. This can be fixed by using HashCode.Combine or tuples instead.
GetHashCodeshouldn't be overriden on mutable types. The hash will change every time the object is mutated, which will break code that relies on it (like dictionaries or hashsets).Another problem I see is that an anonymous object is created every time a hash code is computed, creating unnecesary memory allocations. This can be fixed by using
HashCode.Combineor tuples instead.
I will look into first issue you've mentioned when get home
But the second one - first approach I tried used System.HashCode which did not compile for .NET Framework 4.6.1 & .NET Standard 2.0
There is nuget package Microsoft.Bcl.HashCode which brings support for HashCode in .NET Standard 2.0 but I didn't find any way to get it working in framework 4.6.1 so I had to use anonymous objects.
But the second one - first approach I tried used
System.HashCodewhich did not compile for .NET Framework 4.6.1 & .NET Standard 2.0
Use tuples.
Issues should be solved now
Adding xmldoc addressing what is being compared would be desirable.