コード例 #1
0
        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);
        }
コード例 #2
0
        protected void AssertGetNewInstance <T>(TDiscriminator discriminator)
        {
            var instance = Mapper.GetNewInstance(discriminator);

            Assert.IsInstanceOf <T>(instance);
        }