/// <summary> /// Maps a property to a CSV field. /// </summary> /// <param name="expression">The property to map.</param> /// <returns>The property mapping.</returns> protected virtual CsvPropertyMap Map(Expression <Func <T, object> > expression) { var property = ReflectionHelper.GetProperty(expression); if (PropertyMaps.Any(m => m.Data.Property == property)) { throw new CsvConfigurationException(string.Format("Property '{0}' has already been mapped.", property.Name)); } var propertyMap = new CsvPropertyMap(property); PropertyMaps.Add(propertyMap); return(propertyMap); }
public string GetPropertyMappedFrom(string propertyName, Type typeFrom) { var mapFromProperty = propertyName; if (PropertyMaps.Any(pm => pm.Type2Property == propertyName && pm.Type1 == typeFrom)) { mapFromProperty = PropertyMaps.First(pm => pm.Type2Property == propertyName && pm.Type1 == typeFrom).Type1Property; } else if (PropertyMaps.Any(pm => pm.Type1Property == propertyName && pm.Type2 == typeFrom)) { mapFromProperty = PropertyMaps.First(pm => pm.Type1Property == propertyName && pm.Type2 == typeFrom).Type2Property; } return(mapFromProperty); }