Example #1
0
        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);
        }
Example #2
0
 public static void Deserialize(TestCustomContext t, IBinaryReader reader, CustomContext context)
 {
     t.Value = context.ValueOverride;
 }
Example #3
0
 public static void Serialize(TestCustomContext t, IBinaryWriter writer, CustomContext context)
 {
     writer.Write(context.ValueOverride);
 }