Exemplo n.º 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
    }
Exemplo n.º 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
    }
Exemplo n.º 3
0
    public void StructVirtualMethodWithoutOverride()
    {
        var st = new NoGetHashCodeOverride();

        Allocations.AssertAllocates(() => st.GetHashCode());
    }
Exemplo n.º 4
0
    public void StructBaseGetHashCodeInvocation()
    {
        var st = new WithBaseGetHashCodeInvocation();

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