public CellMetadata GetCellMetadata(Expression <Func <TModel, object> > property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } return(GetCellMetadata(_propertyInfoExtractor.GetPropertyInfo(property))); }
private IDataSheetCell FindMatchingCell <TModel>(PropertyInfo property, IDataSheetRow headerRow, IReadOnlyList <MemberSpec <TModel> > specs) where TModel : class { if (specs.Any()) { var propertySpec = specs.SingleOrDefault( s => _propertyInfoExtractor.GetPropertyInfo(s.DestinationMember).Name == property.Name); if (propertySpec.AnyValue()) { if (propertySpec.Is <IgnoreColumn>()) { LogIgnoringProperty(property); return(null); } return(propertySpec.SelectCellOrThrow(headerRow)); } } var selector = Resolve.ByConvention(property.Name, _conventionsApplier, StringComparison.InvariantCultureIgnoreCase); var cell = selector.SelectCell(headerRow); if (cell == null) { throw new UnmapppedPropertyException(property.Name, headerRow); } return(cell); }
public void ShouldContainMetadataForEachProperty() { // Arrange var propertyInfo = Substitute.For <PropertyInfo>(); propertyInfo.Name.Returns("FirstName", "LastName", "Age"); _propertyInfoExtractor.GetPropertyInfo(Arg.Any <Expression <Func <PersonWithMetadata, object> > >()) .Returns(propertyInfo); // Act var result = _sut.Map <PersonWithMetadata>(SheetName).First(); // Assert Assert.NotNull(result.GetCellMetadata(p => p.FirstName)); Assert.NotNull(result.GetCellMetadata(p => p.LastName)); Assert.NotNull(result.GetCellMetadata(p => p.Age)); }