/// <summary>
 /// Applies a mapping from an open generic abstraction to an open generic concrete type.
 /// </summary>
 /// <param name="tAbstract">The abstract type.</param>
 /// <param name="tConcrete">The concrete type.</param>
 /// <param name="mappingBehavior">The mapping behavior.</param>
 /// <exception cref="JsonTypeMapException">Thrown if <paramref name="tConcrete"/> is an abstract class or an interface or if <paramref name="tConcrete"/> does not inherit from <paramref name="tAbstract"/>.</exception>
 public void MapGeneric(Type tAbstract, Type tConcrete, MapBaseAbstractionBehavior mappingBehavior = MapBaseAbstractionBehavior.Unmapped)
 {
     if (tConcrete.GetTypeInfo().IsAbstract || tConcrete.GetTypeInfo().IsInterface)
     {
         throw new JsonTypeMapException(tAbstract, tConcrete);
     }
     if (!tConcrete.InheritsFrom(tAbstract))
     {
         throw new JsonTypeMapException(tAbstract, tConcrete);
     }
     _MapTypes(tAbstract, tConcrete, mappingBehavior);
 }
        /// <summary>
        /// Applies a mapping from an abstraction to a concrete type.
        /// </summary>
        /// <typeparam name="TAbstract">The abstract type.</typeparam>
        /// <typeparam name="TConcrete">The concrete type.</typeparam>
        /// <param name="mappingBehavior">The mapping behavior.</param>
        /// <exception cref="JsonTypeMapException{TAbstract, TConcrete}">Thrown if TConcrete is an abstract class or an interface.</exception>
        public void Map <TAbstract, TConcrete>(MapBaseAbstractionBehavior mappingBehavior = MapBaseAbstractionBehavior.Unmapped)
            where TConcrete : TAbstract, new()
        {
            if (typeof(TConcrete).GetTypeInfo().IsAbstract || typeof(TConcrete).GetTypeInfo().IsInterface)
            {
                throw new JsonTypeMapException <TAbstract, TConcrete>();
            }
            var tAbstract = typeof(TAbstract);
            var tConcrete = typeof(TConcrete);

            _MapTypes(tAbstract, tConcrete, mappingBehavior);
        }
        private void _MapTypes(Type tAbstract, Type tConcrete, MapBaseAbstractionBehavior mappingBehavior)
        {
            _registry[tAbstract] = tConcrete;
            switch (mappingBehavior)
            {
            case MapBaseAbstractionBehavior.Unmapped:
                _MapBaseTypes(tAbstract, tConcrete, false);
                break;

            case MapBaseAbstractionBehavior.Override:
                _MapBaseTypes(tAbstract, tConcrete, true);
                break;
            }
        }
示例#4
0
 /// <summary>
 /// Applies a mapping from an open generic abstraction to an open generic concrete type.
 /// </summary>
 /// <param name="tAbstract">The abstract type.</param>
 /// <param name="tConcrete">The concrete type.</param>
 /// <param name="mappingBehavior">The mapping behavior.</param>
 /// <exception cref="JsonTypeMapException">Thrown if <paramref name="tConcrete"/> is an
 /// abstract class or an interface or if <paramref name="tConcrete"/> does not inherit
 /// from <paramref name="tAbstract"/>.</exception>
 public static void MapGeneric(Type tAbstract, Type tConcrete, MapBaseAbstractionBehavior mappingBehavior = MapBaseAbstractionBehavior.Unmapped)
 {
     AbstractionMap.Default.MapGeneric(tAbstract, tConcrete, mappingBehavior);
 }
示例#5
0
 /// <summary>
 /// Applies a mapping from an abstraction to a concrete type.
 /// </summary>
 /// <typeparam name="TAbstract">The abstract type.</typeparam>
 /// <typeparam name="TConcrete">The concrete type.</typeparam>
 /// <param name="mappingBehavior">The mapping behavior.</param>
 /// <exception cref="JsonTypeMapException{TAbstract, TConcrete}">Thrown if TConcrete is an
 /// abstract class or an interface.</exception>
 public static void Map <TAbstract, TConcrete>(MapBaseAbstractionBehavior mappingBehavior = MapBaseAbstractionBehavior.Unmapped)
     where TConcrete : TAbstract, new()
 {
     AbstractionMap.Default.Map <TAbstract, TConcrete>(mappingBehavior);
 }