ExcelToEnumerable icon indicating copy to clipboard operation
ExcelToEnumerable copied to clipboard

Add overload for Property mapping using MemberInfo

Open westdavidr opened this issue 2 years ago • 1 comments

westdavidr avatar May 09 '23 18:05 westdavidr

@ChrisHodges - Can you take a look at this PR when you get a chance?

I have a use case where I don't know the Type that is being hydrated from the Excel file, but I am relying on some other source for the column mapping (a custom attribute that I'm using for mapping from csv and xlsx using separate libraries)

foreach ( PropertyInfo propertyInfo in typeof( T ).GetProperties( BindingFlags.Instance | BindingFlags.Public ) )
{
    if ( propertyInfo.GetCustomAttribute<ColumnMap>() is not { } columnMap ) continue;

    opts.Property( propertyInfo ).MapsToColumnNamed( columnMap.Name );
}

I've included tests, and all tests are passing.

westdavidr avatar May 09 '23 18:05 westdavidr