If one has an enumeration stored inside an aggregate type, one might want to include that inside the type's hash code (assuming a typical "multiply by primes" hash function). If one just calls SomeEnum.GetHashCode()
, it appears that the JIT boxes the instance, even in release builds.
Profiling this shows some 10% of the time of my application spent boxing enumerations inside various GetHashCode
functions.
Several value types implement IEquatable
or similar interfaces, which allows calling GetHashCode
as a static method; which avoids the boxing. But System.Enum
doesn't provide the static overload of GetHashCode
. Is there some means of computing the code that should be used but that avoids the boxing?