示例#1
0
        /// <summary>
        /// Registers the class map.
        /// </summary>
        /// <param name="map">The class map to register.</param>
        public void RegisterClassMap(
            ExcelClassMap map)
        {
            if (map.Constructor == null && map.PropertyMaps.Count == 0 && map.ReferenceMaps.Count == 0)
            {
                throw new ExcelConfigurationException("No mappings were specified in the ExcelClassMap.");
            }

            Maps.Add(map);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExcelPropertyReferenceMap"/> class.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="mapping">The <see cref="ExcelClassMap"/> to use for the reference map.</param>
        public ExcelPropertyReferenceMap(
            PropertyInfo property,
            ExcelClassMap mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            _property = property;
            Mapping   = mapping;
        }
        /// <summary>
        /// Adds the specified map for it's record type. If a map
        /// already exists for the record type, the specified
        /// map will replace it.
        /// </summary>
        /// <param name="map">The map.</param>
        internal virtual void Add(
            ExcelClassMap map)
        {
            var type = GetGenericExcelClassMapType(map.GetType()).GetGenericArguments().First();

            if (_data.ContainsKey(type))
            {
                _data[type] = map;
            }
            else
            {
                _data.Add(type, map);
            }
        }
示例#4
0
        /// <summary>
        /// Auto maps the given map and checks for circular references as it goes.
        /// </summary>
        /// <param name="map">The map to auto map.</param>
        internal static void AutoMapInternal(
            ExcelClassMap map)
        {
            var type = map.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 = map.GetMaxIndex() + 1;
                map.PropertyMaps.Add(propertyMap);
            }

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