FileHelpers icon indicating copy to clipboard operation
FileHelpers copied to clipboard

Add an option to ignore private members

Open killergege opened this issue 10 years ago • 2 comments

It would be nice to add an option (in FileHelperEngine.Options ?) to the engine to ignore private / protected fields when importing or exporting. Without this option, the class file may result in having a lot of FieldIgnored attributes in some cases.

killergege avatar Sep 19 '15 16:09 killergege

I'm having the same issue and it looks like making the field Hidden does not solve the issue either...

yannstlo avatar Mar 29 '16 17:03 yannstlo

I think I could benefit from this also. Here is my situation:

Let's say I have 5 fields and I need to skip field 3. If I use FieldHidden, then the field is skipped, but the FieldLength is not taken in to account so all fields read in after that hidden field are not read in correctly (the start index for all subsequent fields is wrong).

I'm thought that FieldHidden would account for the FieldLength, but not actually generate the field in the output object (whether it is a string, list, array, datatable, whatever). However, as @yannstlo stated, this is not the case. I then thought that perhaps NetVisibility.Private or .Protected would do this, but again, as @killergege stated, this is not the case.

Being able to ignore unused columns during an import is rather important. Right now, what I have to do is create a table that has the right schema (call it Table1) and then use FileHelperEngine.ReadFileAsDT( ) to create a new table (call it Table2). I then use DataTable.Copy( ) to stuff Table2 into Table1. This results in fields in Table1 that are appended to the end of the schema and are set to ReadOnly = True. Using that information, I delete all columns from Table1 that are ReadOnly. Kinda tedious and, really, we should have to do this.

breusshe avatar Aug 17 '16 12:08 breusshe