public void ILSerializer_AllowCopiedFieldsToDifferFromSerializedFields() { var input = new FieldTest { One = 1, Two = 2, Three = 3 }; var generator = new ILSerializerGenerator(); var serializers = generator.GenerateSerializer(input.GetType(), f => f.Name != "One", f => f.Name != "Three"); var writer = new SerializationContext(this.fixture.SerializationManager) { StreamWriter = new BinaryTokenStreamWriter() }; var copy = (FieldTest)serializers.DeepCopy(input, writer); Assert.Equal(1, copy.One); Assert.Equal(2, copy.Two); Assert.Equal(0, copy.Three); serializers.Serialize(input, writer, input.GetType()); var reader = new DeserializationContext(this.fixture.SerializationManager) { StreamReader = new BinaryTokenStreamReader(writer.StreamWriter.ToByteArray()) }; var deserialized = (FieldTest)serializers.Deserialize(input.GetType(), reader); Assert.Equal(0, deserialized.One); Assert.Equal(2, deserialized.Two); Assert.Equal(3, deserialized.Three); }
public void ILSerialized_NonSerializedFields() { var input = new FieldTest { One = 1, Two = 2, NonSerializedInt = 1098 }; var generator = new ILSerializerGenerator(); var serializers = generator.GenerateSerializer(input.GetType()); var writer = new SerializationContext(this.fixture.SerializationManager) { StreamWriter = new BinaryTokenStreamWriter() }; serializers.Serialize(input, writer, input.GetType()); var reader = new DeserializationContext(this.fixture.SerializationManager) { StreamReader = new BinaryTokenStreamReader(writer.StreamWriter.ToByteArray()) }; var deserialized = (FieldTest)serializers.Deserialize(input.GetType(), reader); Assert.Equal(input.One, deserialized.One); Assert.Equal(input.Two, deserialized.Two); Assert.NotEqual(input.NonSerializedInt, deserialized.NonSerializedInt); Assert.Equal(default(int), deserialized.NonSerializedInt); }
public void ILSerializer_AllowCopiedFieldsToDifferFromSerializedFields() { var input = new FieldTest { One = 1, Two = 2, Three = 3 }; var generator = new ILSerializerGenerator(); var serializers = generator.GenerateSerializer(input.GetType(), f => f.Name != "One", f => f.Name != "Three"); var copy = (FieldTest)serializers.DeepCopy(input); Assert.Equal(1, copy.One); Assert.Equal(2, copy.Two); Assert.Equal(0, copy.Three); var writer = new BinaryTokenStreamWriter(); serializers.Serialize(input, writer, input.GetType()); var reader = new BinaryTokenStreamReader(writer.ToByteArray()); var deserialized = (FieldTest)serializers.Deserialize(input.GetType(), reader); Assert.Equal(0, deserialized.One); Assert.Equal(2, deserialized.Two); Assert.Equal(3, deserialized.Three); }
public void ILSerializer_LifecycleHooksAreCalled() { var input = new FieldTest(); var generator = new ILSerializerGenerator(); var serializers = generator.GenerateSerializer(input.GetType()); var writer = new SerializationContext(this.fixture.SerializationManager) { StreamWriter = new BinaryTokenStreamWriter() }; serializers.Serialize(input, writer, input.GetType()); var reader = new DeserializationContext(this.fixture.SerializationManager) { StreamReader = new BinaryTokenStreamReader(writer.StreamWriter.ToByteArray()) }; var deserialized = (FieldTest)serializers.Deserialize(input.GetType(), reader); Assert.Null(input.Context); Assert.NotNull(deserialized.Context); Assert.Equal(this.fixture.SerializationManager, deserialized.Context.SerializationManager); }
public void TestEmitField() { var c = new FieldTest(1); var cType = c.GetType(); var cMethod = cType.GetField(nameof(c.Value)); var expected = c.Value; var builder = new ILInstructionBuilder(); builder.Write(OpCodes.Ldarg_0); builder.Write(OpCodes.Ldfld, cMethod.MetadataToken); builder.Write(OpCodes.Ret); var ilMethod = new ILMethod(MethodBase.GetCurrentMethod().Name, expected.GetType()); ilMethod.AddParameters(new[] { cType }); ilMethod.AddInstructions(builder.Instructions.ToArray()); ilMethod.Module = this.GetType().Module; var method = ilMethod.Compile(); var actual = method.Invoke(null, new[] { c }); Assert.IsTrue((int)actual == expected, $"Actual: {actual}\r\nExpected:{expected}"); }
public static void Delete(Flags toDelete, FieldTest fieldTest) { _instance.Delete(toDelete, fieldTest); }
public static void Refresh(FieldTest fieldTest, Flags toPopulate) { _instance.Refresh(new FieldTestList(fieldTest), toPopulate); }
public static void Populate(FieldTest fieldTest, Flags toPopulate) { _instance.Populate(fieldTest, toPopulate); }