Header name containing underscore
acsel87 opened this issue · 1 comments
Hi
I have an excel with header names containing underscores:
ex. Column_Name
I map it using dynamic type (needs to be dynamic in my case):
var rows = mapper.Take<dynamic>("Sheet").ToList();
foreach(var row in rows) {
var value = row.Value;
somObj.ColumnName = value.Column_Name;
}
and it results in the following error:
"does not contain a definition for 'Column_Name' "
If I remove the underscore, it works perfectly.
As a workaround I can look for another naming convention for our headers, but I would like to know if this is a bug or I'm doing something wrong.
----------------------- EDIT ---------------------------------
I looked at the row.Value and it seems that even though in excel the header is Column_Name, when imported, it comes as row.Value.ColumnName (so the underscore, and possibly other characters as well, is removed)
This means there isn't any real issue anymore, but it's still confusing/unintuitive.
Thank you
below chars will be removed from the name to ensure it's a valid property name. source code:
// Default chars that will be removed when mapping by column header name.
private static readonly char[] DefaultIgnoredChars =
{'`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '-', '_', '+', '=', '|', ',', '.', '/', '?'};
if you want to keep the underscore, just write this
// remove underscore
mapper.IgnoredNameChars = {'`', '~', '!', '@', '#', '$', '%', '^', '&', '*', '-', '+', '=', '|', ',', '.', '/', '?'};
but yes, underscore is valid in a property name, I will consider removing it from the default array.