public void CustomContextTest() { var settings = new Settings { SupportSerializationHooks = true } .RegisterCustomSerializer <TestCustomContext, CustomContext>(TestCustomContext.Serialize, TestCustomContext.Deserialize) .MarkSerializable(typeof(TestCustomContext)); var binary = Binary.Create(settings); var m = new MemoryStream(); var x = new TestCustomContext { Value = 10 }; var context = new CustomContext { ValueOverride = 3 }; binary.SetCustomHookContext(context); binary.Write(x, m); m.Seek(0, SeekOrigin.Begin); var y = binary.Read <TestCustomContext>(m); y.Value.Should().Be(3); }
public static void Deserialize(TestCustomContext t, IBinaryReader reader, CustomContext context) { t.Value = context.ValueOverride; }
public static void Serialize(TestCustomContext t, IBinaryWriter writer, CustomContext context) { writer.Write(context.ValueOverride); }