示例#1
0
 public CellMetadata GetCellMetadata(Expression <Func <TModel, object> > property)
 {
     if (property == null)
     {
         throw new ArgumentNullException(nameof(property));
     }
     return(GetCellMetadata(_propertyInfoExtractor.GetPropertyInfo(property)));
 }
示例#2
0
        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);
        }
示例#3
0
        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));
        }