Ejemplo n.º 1
0
        /// <summary>
        /// Returns a custom json converter for abstract classes.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <returns>The contract's default <see cref="T:Newtonsoft.Json.JsonConverter" />.</returns>
        protected override JsonConverter ResolveContractConverter(Type objectType)
        {
            var topLevelBaseType = GetInheritanceHierarchy(objectType).First();

            _typeMaps.TryGetValue(topLevelBaseType, out var typeMap);

            if (typeMap == null)
            {
                return(base.ResolveContractConverter(objectType));
            }

            return(new BaseClassJsonConverter(topLevelBaseType, typeMap));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a custom json converter for abstract classes.
        /// </summary>
        protected override JsonConverter ResolveContractConverter(Type objectType)
        {
            Type topLevelBaseType = GetInheritanceHierarchy(objectType).First();

            IReadOnlyDictionary <string, Type> typeMap;

            _typeMaps.TryGetValue(topLevelBaseType, out typeMap);

            if (typeMap == null)
            {
                return(base.ResolveContractConverter(objectType));
            }

            return(new BaseClassJsonConverter(topLevelBaseType, typeMap));
        }