public void StrangeTest() { var strange = new Strange(); Assert.AreEqual(-(1 / 3), strange.Charge); Assert.AreEqual(-1, strange.Strangeness); }
public void SerializaeWithLengthPrefixShouldWorkWithBase128() { var original = new Strange { Foo = "abc", Bar = 123 }; // serialize and deserialize with base-128 using (MemoryStream ms = new MemoryStream()) { Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Base128, 1); ms.Position = 0; object obj; Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms, PrefixStyle.Base128, i => typeof(Strange), out obj); var clone = (Strange)obj; Assert.AreNotSame(original, clone); Assert.IsNotNull(clone); Assert.AreEqual(original.Foo, clone.Foo, "Foo"); Assert.AreEqual(original.Bar, clone.Bar, "Bar"); } }
public static void Main(string[] args) { Strange bar = null; var hello = new DynamicMethod("ThisIsNull", typeof(void), new[] { typeof(Strange) }, typeof(Strange).Module); ILGenerator il = hello.GetILGenerator(256); il.Emit(OpCodes.Ldarg_0); var foo = typeof(Strange).GetMethod("Foo"); il.Emit(OpCodes.Call, foo); il.Emit(OpCodes.Ret); var print = (HelloDelegate)hello.CreateDelegate(typeof(HelloDelegate)); print(bar); Console.ReadLine(); }
public void SerializeWithLengthPrefixShouldWorkWithBase128() { var original = new Strange { Foo = "abc", Bar = 123 }; // serialize and deserialize with base-128 using (MemoryStream ms = new MemoryStream()) { Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Base128, 1); ms.Position = 0; Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms, PrefixStyle.Base128, _ => typeof(Strange), out object obj); var clone = (Strange)obj; Assert.NotSame(original, clone); Assert.NotNull(clone); Assert.Equal(original.Foo, clone.Foo); //, "Foo"); Assert.Equal(original.Bar, clone.Bar); //, "Bar"); } }
public void SerializeWithLengthPrefixShouldWorkWithFixed32() { var original = new Strange { Foo = "abc", Bar = 123 }; // serialize and deserialize with fixed-32 using MemoryStream ms = new MemoryStream(); Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Fixed32, 1); ms.Position = 0; // BOOM here; oh how embarrassing #pragma warning disable CS0618 Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms, PrefixStyle.Fixed32, _ => typeof(Strange), out object obj); #pragma warning restore CS0618 var clone = (Strange)obj; Assert.NotSame(original, clone); Assert.NotNull(clone); Assert.Equal(original.Foo, clone.Foo); //, "Foo"); Assert.Equal(original.Bar, clone.Bar); //, "Bar"); }
public void SerializeWithLengthPrefixShouldWorkWithFixed32() { var original = new Strange { Foo = "abc", Bar = 123 }; // serialize and deserialize with fixed-32 using (MemoryStream ms = new MemoryStream()) { Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Fixed32, 1); ms.Position = 0; object obj; // BOOM here; oh how embarrassing Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms, PrefixStyle.Fixed32, i => typeof(Strange), out obj); var clone = (Strange)obj; Assert.AreNotSame(original, clone); Assert.IsNotNull(clone); Assert.AreEqual(original.Foo, clone.Foo, "Foo"); Assert.AreEqual(original.Bar, clone.Bar, "Bar"); } }