public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jObject = JObject.Load(reader); var name = _propertyNameTransformer(_discriminatorMapper.DiscriminatorName); var raw = jObject[name].ToString(); var discriminator = _discriminatorMapper.Discriminator(raw); var instance = _discriminatorMapper.GetNewInstance(discriminator); serializer.Populate(jObject.CreateReader(), instance); return(instance); }
protected void AssertGetNewInstance <T>(TDiscriminator discriminator) { var instance = Mapper.GetNewInstance(discriminator); Assert.IsInstanceOf <T>(instance); }