Exemplo n.º 1
0
        /// <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?");
            }

            configuration.ApplyClassAttributes(type);

            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);
        }