public void Write_Should_use_context_unmarshalling_When_sub_field() { using Stream stream = new MemoryStream(); using TextSerializationContext context = new TextSerializationContext() .Unmarshal <int, int>(i => i * 2); Write(stream, new Point(1, 2)); stream.Position = 0; Point copy = TextSerializer.Read <Point>(stream, context); Check.That(copy).IsEqualTo(new Point(2, 4)); }
public void Write_Should_use_context_unmarshalling_for_object() { using Stream stream = new MemoryStream(); using TextSerializationContext context = new TextSerializationContext() .Unmarshal <int, string>(i => $"value {i}"); Write <object>(stream, 42); stream.Position = 0; object copy = TextSerializer.Read <object>(stream, context); Check.That(copy).IsInstanceOf <string>().And.IsEqualTo("value 42"); }
public void Write_Should_use_context_unmarshalling_When_same_type() { using Stream stream = new MemoryStream(); using TextSerializationContext context = new TextSerializationContext() .Unmarshal <int, int>(_ => 1337); Write(stream, 42); stream.Position = 0; int copy = TextSerializer.Read <int>(stream, context); Check.That(copy).IsEqualTo(1337); }
protected override T Read <T>(Stream stream) => TextSerializer.Read <T>(stream);