Example #1
0
        /// <summary>
        /// Maps a property to a Excel field.
        /// </summary>
        /// <param name="property">Property to map</param>
        /// <returns>The property mapping.</returns>
        private ExcelPropertyMap Map(
            PropertyInfo property)
        {
            var existingMap = PropertyMaps.SingleOrDefault(m => m.Data.Property == property);

            if (existingMap != null)
            {
                return(existingMap);
            }

            var propertyMap = new ExcelPropertyMap(property);

            propertyMap.Data.Index = GetMaxIndex() + 1;
            PropertyMaps.Add(propertyMap);

            return(propertyMap);
        }
Example #2
0
        /// <summary>
        /// Auto maps the given map and checks for circular references as it goes.
        /// </summary>
        /// <param name="mapBase">The map to auto map.</param>
        internal static void AutoMapInternal(
            ExcelClassMapBase mapBase)
        {
            var type = mapBase.GetType().BaseType.GetGenericArguments()[0];

            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                throw new ExcelConfigurationException("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?");
            }

            // Process all the properties in this type
            foreach (var property in type.GetProperties())
            {
                var propertyMap = new ExcelPropertyMap(property);
                propertyMap.Data.Index = mapBase.GetMaxIndex() + 1;
                mapBase.PropertyMaps.Add(propertyMap);
            }

            // Re-index all the properties when we are done
            mapBase.ReIndex();
        }