public void RuntimeHelpers_RunClassConstructor() { RuntimeTypeHandle t = typeof(HasCctor).TypeHandle; RuntimeHelpers2.RunClassConstructor(t); Assert.AreEqual(HasCctorReceiver.S, "Hello"); return; }
public unsafe void RuntimeHelpers_GetObjectValue() { // Object RuntimeHelpers2.GetObjectValue(Object) TestStruct t = new TestStruct() { i1 = 2, i2 = 4 }; object tOV = RuntimeHelpers2.GetObjectValue(t); Assert.AreEqual(t, (TestStruct)tOV); object o = new object(); object oOV = RuntimeHelpers2.GetObjectValue(o); Assert.AreEqual(o, oOV); int i = 3; object iOV = RuntimeHelpers2.GetObjectValue(i); Assert.AreEqual(i, (int)iOV); }
public void RuntimeHelpers_GetHashCodeTest() { // Int32 RuntimeHelpers2.GetHashCode(Object) object obj1 = new object(); int h1 = RuntimeHelpers2.GetHashCode(obj1); int h2 = RuntimeHelpers2.GetHashCode(obj1); Assert.AreEqual(h1, h2); object obj2 = new object(); int h3 = RuntimeHelpers2.GetHashCode(obj2); Assert.AreNotEqual(h1, h3); // Could potentially clash but very unlikely int i123 = 123; int h4 = RuntimeHelpers2.GetHashCode(i123); Assert.AreNotEqual(i123.GetHashCode(), h4); int h5 = RuntimeHelpers2.GetHashCode(null); Assert.AreEqual(h5, 0); }