Beispiel #1
0
    public static void  RuntimeMethodHandleTest()
    {
        MethodInfo          mi = typeof(Base).GetMethod(nameof(Base.MyMethod));
        RuntimeMethodHandle h  = mi.MethodHandle;

        Assert.Equal(mi, MethodBase.GetMethodFromHandle(h));

        Assert.True(h.Value != IntPtr.Zero);

        Assert.Equal(h.GetHashCode(), h.GetHashCode());
        Assert.Equal(default(RuntimeMethodHandle).GetHashCode(), default(RuntimeMethodHandle).GetHashCode());

        Assert.True(h.Equals(h));
        Assert.False(h.Equals(default(RuntimeMethodHandle)));
        Assert.False(default(RuntimeMethodHandle).Equals(h));
        Assert.True(default(RuntimeMethodHandle).Equals(default(RuntimeMethodHandle)));

        Assert.True(h.Equals((object)h));
        Assert.True(((IEquatable <RuntimeMethodHandle>)h).Equals(h));
        Assert.False(h.Equals(new object()));
        Assert.False(h.Equals(null));

        Assert.False(h == default(RuntimeMethodHandle));
        Assert.True(h != default(RuntimeMethodHandle));
    }
Beispiel #2
0
    public static void  RuntimeMethodHandleTest()
    {
        MethodInfo          mi = typeof(Base).GetMethod(nameof(Base.MyMethod));
        RuntimeMethodHandle h  = mi.MethodHandle;

        Assert.Equal(mi, MethodBase.GetMethodFromHandle(h));

        Assert.True(h.Value != IntPtr.Zero);

        Assert.Equal(h.GetHashCode(), h.GetHashCode());
        Assert.Equal(default(RuntimeMethodHandle).GetHashCode(), default(RuntimeMethodHandle).GetHashCode());

        Assert.True(h.Equals(h));
        Assert.False(h.Equals(default(RuntimeMethodHandle)));
        Assert.False(default(RuntimeMethodHandle).Equals(h));
        Assert.True(default(RuntimeMethodHandle).Equals(default(RuntimeMethodHandle)));

        Assert.True(h.Equals((object)h));
        Assert.True(((IEquatable <RuntimeMethodHandle>)h).Equals(h));
        Assert.False(h.Equals(new object()));
        Assert.False(h.Equals(null));

        Assert.False(h == default(RuntimeMethodHandle));
        Assert.True(h != default(RuntimeMethodHandle));

        IntPtr hPtr = RuntimeMethodHandle.ToIntPtr(h);
        RuntimeMethodHandle hNew = RuntimeMethodHandle.FromIntPtr(hPtr);

        Assert.True(h.Equals(hNew));
        Assert.True(hNew.Equals(h));

        // Confirm the created handle is valid
        Assert.Equal(mi, MethodBase.GetMethodFromHandle(hNew));
    }
Beispiel #3
0
    public static void DefaultRuntimeMethodHandleHashCodeTest()
    {
        RuntimeMethodHandle rmh1 = new RuntimeMethodHandle();
        RuntimeMethodHandle rmh2 = new RuntimeMethodHandle();

        Assert.Equal(rmh1.GetHashCode(), rmh2.GetHashCode());
    }
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("Verify cloned instance has the same hashcode of it original...");

        try
        {
            RuntimeMethodHandle myHandle1 = new RuntimeMethodHandle();
            RuntimeMethodHandle myHandle2 = myHandle1;

            if (myHandle1.GetHashCode() != myHandle2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("003", "The two instances should have the same hashcode!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception occurs: " + e);
            return(retVal);
        }

        return(retVal);
    }
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("Verify different instances of RuntimeMethodGetHashCode...");

        try
        {
            RuntimeMethodHandle myHandle1 = new RuntimeMethodHandle();
            RuntimeMethodHandle myHandle2 = new RuntimeMethodHandle();

            if (myHandle1.GetHashCode() != myHandle2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001", "The two instance should have the same HashCode!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception occurs: " + e);
            retVal = false;
        }

        return(retVal);
    }
    public bool PosTest2()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("Verify cloned instance has the same hashcode of it original...");

        try
        {
            RuntimeMethodHandle myHandle1 = new RuntimeMethodHandle();
            RuntimeMethodHandle myHandle2 = myHandle1;

            if (myHandle1.GetHashCode() != myHandle2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("003","The two instances should have the same hashcode!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004","Unexpected exception occurs: " + e);
            return retVal;
        }

        return retVal;
    }
    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("Verify different instances of RuntimeMethodGetHashCode...");

        try
        {
            RuntimeMethodHandle myHandle1 = new RuntimeMethodHandle();
            RuntimeMethodHandle myHandle2 = new RuntimeMethodHandle();

            if (myHandle1.GetHashCode() != myHandle2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001","The two instance should have the same HashCode!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002","Unexpected exception occurs: " + e);
            retVal = false;
        }

        return retVal;
    }
 public override int GetHashCode() => _handle.GetHashCode();