示例#1
0
    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
    }
示例#2
0
    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
    }
示例#3
0
    public void RecordStructGetHashCodeInvocation()
    {
        var st = new RecordStruct();

        Allocations.AssertNoAllocations(() => st.GetHashCode());
    }
示例#4
0
    public void NullableStructVirtualMethodWithOverride()
    {
        WithGetHashCodeOverride?st = new WithGetHashCodeOverride();

        Allocations.AssertNoAllocations(() => st.GetHashCode());
    }