C# 所有属性上的字段引号

C# 所有属性上的字段引号,c#,csv,filehelpers,C#,Csv,Filehelpers,是否有类似FieldQuotes的属性可以应用于属性 另外,是否可以自动将FieldQuotes添加到所有字段,这样我就不必为每个字段定义它?您要查找的属性是FieldQuoted。文件是 一些例子: [FieldQuoted()] // Quoted with " public string CustomerName [FieldQuoted('[')] // Quoted between [brackets] public string CustomerName [FieldQuoted

是否有类似FieldQuotes的属性可以应用于属性


另外,是否可以自动将FieldQuotes添加到所有字段,这样我就不必为每个字段定义它?

您要查找的属性是
FieldQuoted
。文件是

一些例子:

[FieldQuoted()] // Quoted with "
public string CustomerName

[FieldQuoted('[')] // Quoted between [brackets]
public string CustomerName

[FieldQuoted('"', QuoteMode.OptionalForBoth)] // Optional quoted when read or write
public string CustomerName

[FieldQuoted('"', MultilineMode.AllowForBoth)] // Indicates that the quoted string can span multiple lines
public string CustomerName

您确实需要应用于每个字段。

但我不能将其应用于属性。您不应该在FileHelpers类中使用属性。使用FileHelpers的最佳方法是将record类视为文件格式的“规范”。使用它来描述仅使用公共字段的文件(是的,这违反了C#最佳实践,我知道…)。一旦将文件加载到
MyFileHelpersClass[]
数组中,就可以将值(例如,使用
foreach
)映射到一个更合理的类,该类具有属性、方法、附加功能等。