CsvFile Header 行不匹配输出,ex(Header = Tol +, Console output = Tol_plus) C#,csvHelper

CsvFile Header Row does not match output, ex(Header = Tol +, Console output = Tol_plus) C#,csvHelper

您好,我正在使用 csvHelper 解析 csvFile,但遇到了障碍。 header 中的 header 之一是 "Tol +"。我无法将其作为变量名,因此我使用自动映射将其映射为 "Tol_plus" class。但是,当我输出文件时,我收到:

(Console output of Header Row below)
Measurement,Nominal,Tol_plus

我想要的:

(How Header Row  actually looks below)
Measurement,Nominal,Tol +

这是我目前的代码:

public class Foo
        {

            public string Measurement { get; set; }//read as string
            public string Nominal { get; set; } //reads in data from here
            public string Tol_plus { get; set; }//reads in data from here 
        }

public sealed class FooMap : ClassMap<Foo>
        {
            public FooMap()
            {
                Map(m => m.Measurement).Name("Measurement");//maps the variables from the class above to things in quotes
                Map(m => m.Nominal).Name("Nominal");

                Map(m => m.Tol_plus).Name("Tol +");
            }
        }
//main method
void main()
 var textwriter = Console.Out;
             using (var csvWriter = new CsvWriter(textwriter, CultureInfo.InvariantCulture))
             using (var reader = new StreamReader(@"path.csv"))
             using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
             {
                csv.Read();
                csv.ReadHeader();
                csv.Configuration.RegisterClassMap<FooMap>();//necessary for mapping 
                var records = csv.GetRecords<Foo>();
                csvWriter.WriteRecords(records);
              }
//The output here gives me: 
Measurement,Nominal,Tol_plus

为此,我尝试将字符串文字传递到 Tol_plus 中,但这没有用,是否有办法映射它以便打印出 "Tol +" 而不是 "Tol_plus"?

根据埃德尼的评论:

public class Foo
        {

            public string Measurement { get; set; }//read as string
            public string Nominal { get; set; } //reads in data from here

            [CsvHelper.Configuration.Attributes.Name("Tol +")]
            public string Tol_plus { get; set; }//reads in data from here 
        }

通过添加行:

[CsvHelper.Configuration.Attributes.Name("Tol +")]

它在输出过程中将名称更改为"Tol +"。