public void EnumGetHashCodeInvocation() { var e = GetHashCode() % 2 == 0 ? ConsoleKey.Clear : ConsoleKey.Add; #if NETFRAMEWORK Allocations.AssertAllocates(() => e.GetHashCode()); Allocations.AssertAllocates(() => e.ToString()); Allocations.AssertAllocates(() => e.Equals(null)); #else Allocations.AssertNoAllocations(() => e.GetHashCode()); // optimized by runtime Allocations.AssertAllocates(() => e.ToString()); Allocations.AssertAllocates(() => e.Equals(null)); #endif }
public void NullableEnumGetHashCodeInvocation() { ConsoleKey?e = GetHashCode() % 2 == 0 ? ConsoleKey.Clear : ConsoleKey.Add; object boxedComparand = ConsoleKey.Clear; #if NETFRAMEWORK Allocations.AssertAllocates(() => e.GetHashCode()); Allocations.AssertAllocates(() => e.ToString()); Allocations.AssertNoAllocations(() => e.Equals(null)); // shortcut Allocations.AssertAllocates(() => e.Equals(boxedComparand)); #else Allocations.AssertNoAllocations(() => e.GetHashCode()); // optimized by runtime Allocations.AssertAllocates(() => e.ToString()); Allocations.AssertNoAllocations(() => e.Equals(null)); // shortcut Allocations.AssertAllocates(() => e.Equals(boxedComparand)); #endif }
public void RecordStructGetHashCodeInvocation() { var st = new RecordStruct(); Allocations.AssertNoAllocations(() => st.GetHashCode()); }
public void NullableStructVirtualMethodWithOverride() { WithGetHashCodeOverride?st = new WithGetHashCodeOverride(); Allocations.AssertNoAllocations(() => st.GetHashCode()); }