예제 #1
0
        /// <summary>
        /// Maps a single row of a sheet to an object using a registered mapping. If no map is registered for this
        /// type then the type will be automapped. This method will not read the sheet's heading if the sheet has a
        /// heading and the heading has not yet been read.
        /// </summary>
        /// <typeparam name="T">The type of the object to map a single row to.</typeparam>
        /// <param name="value">An object of type T mapped from a single row in the sheet.</param>
        /// <returns>False if there are no more rows in the sheet or the row cannot be mapped to an object, else false.</returns>
        public bool TryReadRow <T>(out T value)
        {
            value = default(T);
            if (!Reader.Read())
            {
                return(false);
            }

            CurrentIndex++;

            if (!Configuration.TryGetClassMap <T>(out ExcelClassMap classMap))
            {
                if (!AutoMapper.AutoMapClass(FallbackStrategy.ThrowIfPrimitive, out ExcelClassMap <T> autoClassMap))
                {
                    throw new ExcelMappingException($"Cannot auto-map type \"{typeof(T)}\".");
                }

                classMap = autoClassMap;
                Configuration.RegisterClassMap(autoClassMap);
            }

            value = (T)classMap.Execute(this, CurrentIndex, Reader);
            return(true);
        }