C# 忽略FileHelpers中的属性

C# 忽略FileHelpers中的属性,c#,attributes,filehelpers,C#,Attributes,Filehelpers,我正在使用将模型导出到CSV。它有一个[fieldnotinfle]属性,在导出时排除字段,但我需要使用属性,因为我还需要从另一个仅使用属性的第三方库中使用其他属性 有没有办法让FileHelpers忽略属性?FileHelpers类只是一种使用有限的C语法作为定义语言来定义平面文件规范的方法。因此,FileHelpers类是一种不寻常的C类,您不应该尝试以任何其他方式使用它们。将FileHelpers类视为CSV格式的“规范”。这应该是它唯一的作用。如果在您的案例中需要一个更“正常”的对象中的

我正在使用将模型导出到CSV。它有一个[fieldnotinfle]属性,在导出时排除字段,但我需要使用属性,因为我还需要从另一个仅使用属性的第三方库中使用其他属性


有没有办法让FileHelpers忽略属性?

FileHelpers类只是一种使用有限的C语法作为定义语言来定义平面文件规范的方法。因此,FileHelpers类是一种不寻常的C类,您不应该尝试以任何其他方式使用它们。将FileHelpers类视为CSV格式的“规范”。这应该是它唯一的作用。如果在您的案例中需要一个更“正常”的对象中的记录,则需要属性而不是字段,然后将结果映射到如下更好的对象:

FileHelperEngine engine = new FileHelperEngine<FileHelpersOrder>(); 
var records = engine.ReadFile("FileIn.txt");

var niceOrders = records.Select(
    x => new NiceOrder() 
       { Number = x.Number,  
         Customer = x.Customer 
         // etc.
       });
[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;
}
其中FileHelperOrder是您的CSV规范,NiceOrder类是一个适当的OOP类,根据需要具有属性、方法等


如果要导出,则需要执行相反的操作,即从NiceOrder集合中选择FileHelperOrder集合。

前几天我遇到了同样的问题,并使用了[FieldHidden]属性。大概是这样的:

FileHelperEngine engine = new FileHelperEngine<FileHelpersOrder>(); 
var records = engine.ReadFile("FileIn.txt");

var niceOrders = records.Select(
    x => new NiceOrder() 
       { Number = x.Number,  
         Customer = x.Customer 
         // etc.
       });
[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;
}

我通过给属性一个支持字段并将支持字段标记为[FieldHidden]来实现这一点:


自3.27版以来,您可以在字段和属性上使用[FieldHidden]