I am using FileHelpers for exporting models to CSV. It has a [FieldNotInFile()] attribute which excludes fields when exporting, but I need to use properties as I need to some other attributes as well from another 3rd party library which only work with properties.
Is there any way to get FileHelpers to ignore a property?
I had the same problem the other day and used [FieldHidden]
attribute. Something like this:
[DelimitedRecord("\t")]
public class PolicyFileRecord
{
public string FileDate;
public int ProgramId;
public string LocationAddress1;
public string LocationAddress2;
public string LocationAddress3;
public string LocationCity;
public string LocationState;
public string LocationZip;
[FieldHidden]
public string LocationCountry;
}
I got this to work by giving the property a backing field and marking the backing field as [FieldHidden]
:
[DelimitedRecord(",")]
public class Record
{
public int Id;
public string Name;
public string SomeProperty
{
get { return someProperty; }
set { someProperty = value; }
}
[FieldHidden]
private string someProperty;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With