/// <summary>
        /// Auto maps all members for the given type. If a member
        /// is mapped again it will override the existing map.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public virtual void AutoMap(Configuration configuration)
        {
            var type = GetGenericType();

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                throw new ConfigurationException("Types that inherit IEnumerable cannot be auto mapped. " +
                                                 "Did you accidentally call GetRecord or WriteRecord which " +
                                                 "acts on a single record instead of calling GetRecords or " +
                                                 "WriteRecords which acts on a list of records?");
            }

            var mapParents = new LinkedList <Type>();

            if (configuration.ShouldUseConstructorParameters(type))
            {
                // This type doesn't have a parameterless constructor so we can't create an
                // instance and set it's member. Constructor parameters need to be created
                // instead. Writing only uses getters, so members will also be mapped
                // for writing purposes.
                AutoMapConstructorParameters(this, configuration, mapParents);
            }

            AutoMapMembers(this, configuration, mapParents);
        }
        /// <summary>
        /// Auto maps the given map using constructor parameters.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="mapParents">The list of parents for the map.</param>
        /// <param name="indexStart">The index starting point.</param>
        protected virtual void AutoMapConstructorParameters(ClassMap map, Configuration configuration, LinkedList <Type> mapParents, int indexStart = 0)
        {
            var type        = map.GetGenericType();
            var constructor = configuration.GetConstructor(map.ClassType);
            var parameters  = constructor.GetParameters();

            foreach (var parameter in parameters)
            {
                var typeConverterType = configuration.TypeConverterCache.GetConverter(parameter.ParameterType).GetType();

                var parameterMap = new ParameterMap(parameter);

                //var memberTypeInfo = parameter.ParameterType.GetTypeInfo();
                var memberType         = parameter.ParameterType;
                var isDefaultConverter = typeConverterType == typeof(DefaultTypeConverter);
                //if( isDefaultConverter && ( memberTypeInfo.HasParameterlessConstructor() || memberTypeInfo.IsUserDefinedStruct() ) )
                if (isDefaultConverter && (memberType.HasParameterlessConstructor() || memberType.IsUserDefinedStruct()))
                {
                    // If the type is not one covered by our type converters
                    // and it has a parameterless constructor, create a
                    // reference map for it.

                    if (configuration.IgnoreReferences)
                    {
                        //throw new InvalidOperationException( $"Configuration '{nameof( configuration.IgnoreReferences )}' can't be true " +
                        throw new InvalidOperationException(string.Format("Configuration '{0}' can't be true ", nameof(configuration.IgnoreReferences)) +
                                                            "when using types without a default constructor. Constructor parameters " +
                                                            "are used and all members including references must be used.");
                    }

                    if (CheckForCircularReference(parameter.ParameterType, mapParents))
                    {
                        //throw new InvalidOperationException( $"A circular reference was detected in constructor paramter '{parameter.Name}'." +
                        throw new InvalidOperationException(string.Format("A circular reference was detected in constructor paramter '{0}'.", parameter.Name) +
                                                            "Since all parameters must be supplied for a constructor, this parameter can't be skipped.");
                    }

                    mapParents.AddLast(type);
                    var refMapType = typeof(DefaultClassMap <>).MakeGenericType(parameter.ParameterType);
                    var refMap     = (ClassMap)ReflectionHelper.CreateInstance(refMapType);
                    AutoMapMembers(refMap, configuration, mapParents, Math.Max(map.GetMaxIndex() + 1, indexStart));
                    mapParents.Drop(mapParents.Find(type));

                    var referenceMap = new ParameterReferenceMap(parameter, refMap);
                    if (configuration.ReferenceHeaderPrefix != null)
                    {
                        //referenceMap.Data.Prefix = configuration.ReferenceHeaderPrefix( memberTypeInfo.MemberType(), memberTypeInfo.Name );
                        referenceMap.Data.Prefix = configuration.ReferenceHeaderPrefix(memberType, memberType.Name);
                    }

                    parameterMap.ReferenceMap = referenceMap;
                }
                else if (configuration.ShouldUseConstructorParameters(parameter.ParameterType))
                {
                    mapParents.AddLast(type);
                    var constructorMapType = typeof(DefaultClassMap <>).MakeGenericType(parameter.ParameterType);
                    var constructorMap     = (ClassMap)ReflectionHelper.CreateInstance(constructorMapType);
                    // Need to use Max here for nested types.
                    AutoMapConstructorParameters(constructorMap, configuration, mapParents, Math.Max(map.GetMaxIndex() + 1, indexStart));
                    mapParents.Drop(mapParents.Find(type));

                    parameterMap.ConstructorTypeMap = constructorMap;
                }
                else
                {
                    parameterMap.Data.TypeConverterOptions = TypeConverterOptions.Merge(new TypeConverterOptions(), configuration.TypeConverterOptionsCache.GetOptions(parameter.ParameterType), parameterMap.Data.TypeConverterOptions);
                    parameterMap.Data.Index = map.GetMaxIndex() + 1;
                }

                map.ParameterMaps.Add(parameterMap);
            }

            map.ReIndex(indexStart);
        }