public void UsingISerializationSurrogates()
        {
            var surrogateSelector = new SurrogateSelector();
            var streamingContext = new StreamingContext(StreamingContextStates.All);
            surrogateSelector.AddSurrogate(typeof(ClassWithSurrogate), streamingContext, new SurrogateClass());
            var serializer = new FudgeSerializer(context);
            serializer.TypeMap.RegisterSurrogateSelector(surrogateSelector);

            // Check out the surrogate
            var surrogate = serializer.TypeMap.GetSurrogate(typeof(ClassWithSurrogate));
            Assert.IsType<DotNetSerializationSurrogateSurrogate>(surrogate);
            Assert.IsType<SurrogateClass>(((DotNetSerializationSurrogateSurrogate)surrogate).SerializationSurrogate);

            var obj1 = new ClassWithSurrogate { A = 22 };
            var msg = serializer.SerializeToMsg(obj1);
            var obj2 = (ClassWithSurrogate)serializer.Deserialize(msg);

            Assert.Equal(obj1.A, obj2.A);
        }
Beispiel #2
0
        public void UsingISerializationSurrogates()
        {
            var surrogateSelector = new SurrogateSelector();
            var streamingContext  = new StreamingContext(StreamingContextStates.All);

            surrogateSelector.AddSurrogate(typeof(ClassWithSurrogate), streamingContext, new SurrogateClass());
            var serializer = new FudgeSerializer(context);

            serializer.TypeMap.RegisterSurrogateSelector(surrogateSelector);

            // Check out the surrogate
            var surrogate = serializer.TypeMap.GetSurrogate(typeof(ClassWithSurrogate));

            Assert.IsType <DotNetSerializationSurrogateSurrogate>(surrogate);
            Assert.IsType <SurrogateClass>(((DotNetSerializationSurrogateSurrogate)surrogate).SerializationSurrogate);

            var obj1 = new ClassWithSurrogate {
                A = 22
            };
            var msg  = serializer.SerializeToMsg(obj1);
            var obj2 = (ClassWithSurrogate)serializer.Deserialize(msg);

            Assert.Equal(obj1.A, obj2.A);
        }