CSV辅助人员中的列的完全合格的名称(避免重复列名称并确保掌握权)
我要求CSV的标头代表对象上属性的完全资格的名称 /路径,以确保转换为CSV时的势力。
一个示例:如果对象具有相同类型的多个属性,则我希望完全符合名称。 Consider the following structure:
public class Foo
{
public DateTime? MyDateTime { get; set; }
public string? MyDescription { get; set; }
}
public class MyContainer
{
public Foo? MyFirstUsage { get; set; }
public Foo? MySecondUsage { get; set; }
}
Under normal circumstances csv helper would create the header for 'MyContainer' as "MyDateTime,MyDescription,MyDateTime,MyDescription"
I'd like to avoid this and qualify the names resulting in a header of "MyFirstUsageMyDateTime,MyFirstUsageMyDescription,MySecondUsageMyDateTime ,mysecondusagemydescription“
tl; dr:如何覆盖csvhelper扁平的对象写入标头,从而使标头代表属性的完全合格的路径,从而(理论上)确保了势力?
编辑:我创建了一个小型示例应用程序,希望更好地解释问题: https://github.com /jimhume/csvhelpercolumnnames/tree/main
edit2:我忘了提到一个要求是为了通过映射而不是通过映射完成 - 需要动态地完成。
I require the header of a CSV to represent the fully qualified name / path of properties on an object to ensure idempotency when converting to csv.
An example: if an object has multiple properties of the same type I would like to fully qualify the name. Consider the following structure:
public class Foo
{
public DateTime? MyDateTime { get; set; }
public string? MyDescription { get; set; }
}
public class MyContainer
{
public Foo? MyFirstUsage { get; set; }
public Foo? MySecondUsage { get; set; }
}
Under normal circumstances csv helper would create the header for 'MyContainer' as "MyDateTime,MyDescription,MyDateTime,MyDescription"
I'd like to avoid this and qualify the names resulting in a header of "MyFirstUsageMyDateTime,MyFirstUsageMyDescription,MySecondUsageMyDateTime,MySecondUsageMyDescription"
TL;DR: how can one override the way CSVHelper flattens objects to write the header so that the header represents the fully qualified path of a property, thus (theoretically) ensuring idempotency?
Edit: I created a small sample app to hopefully better explain the issue: https://github.com/JimHume/CsvHelperColumnNames/tree/main
Edit2: I forgot to mention that one requirement is for this to not be done via mapping--it needs to be done dynamically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Update :发现您可以在配置中使用
Reference Headerprefix
。Update: Discovered you can use
ReferenceHeaderPrefix
in the configuration.