Beispiel #1
0
    public static void  RuntimeTypeHandleTest()
    {
        RuntimeTypeHandle h = typeof(int).TypeHandle;

        Assert.NotEqual(h, typeof(uint).TypeHandle);

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

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

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

        Assert.True(h.Equals((object)h));
        Assert.True(((IEquatable <RuntimeTypeHandle>)h).Equals(h));
        Assert.False(h.Equals(typeof(int)));
        Assert.False(h.Equals(new object()));
        Assert.False(h.Equals(null));

        Assert.False(h == null);
        Assert.False(null == h);
        Assert.True(h != null);
        Assert.True(null != h);

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

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