public void CanDoCustomTypeResolveByResolvingToDifferentType()
        {
            // arrange
            serializer.AddTypeResolver(d =>
            {
                if (d.TypeName == "Rebus.Tests.Serialization.Json.TestJsonMessageSerializer+SomeMessage")
                {
                    return(typeof(SomeDucktypinglyCompatibleMessage));
                }
                return(null);
            });

            // act
            var message = RoundtripMessage(new SomeMessage {
                SomeField = "hello!"
            });

            // assert
            message.ShouldBeOfType <SomeDucktypinglyCompatibleMessage>();
            ((SomeDucktypinglyCompatibleMessage)message).SomeField.ShouldBe("hello!");
        }
Beispiel #2
0
 /// <summary>
 /// Adds a function that will determine how a given <see cref="TypeDescriptor"/> is turned into a .NET type.
 /// Return null if the function has no opinion about this particular type descriptor, allowing other functions and
 /// ultimately the default JSON serializer's opinion to be used.
 /// </summary>
 public JsonSerializationOptions AddTypeResolver(Func <TypeDescriptor, Type> resolve)
 {
     jsonMessageSerializer.AddTypeResolver(resolve);
     return(this);
 }