Ejemplo n.º 1
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="ExcelClassMapBase"/> to use for the reference map.</param>
 public ExcelPropertyReferenceMap(
     PropertyInfo property,
     ExcelClassMapBase mapping)
 {
     _property = property ?? throw new ArgumentNullException(nameof(property));
     Mapping   = mapping ?? throw new ArgumentNullException(nameof(mapping));
 }
Ejemplo n.º 2
0
        /// <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="mapBase">The map.</param>
        internal virtual void Add(
            ExcelClassMapBase mapBase)
        {
            var type = GetGenericExcelClassMapType(mapBase.GetType()).GetGenericArguments().First();

            if (_data.ContainsKey(type))
            {
                _data[type] = mapBase;
            }
            else
            {
                _data.Add(type, mapBase);
            }
        }
Ejemplo n.º 3
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();
        }