CSV Helper AutoMap 列表对象?
我目前正在尝试让我的 CSV Helper AutoMap 类写出 List<> 的列标题/值。我的其他班级的财产。由于某种原因,自动映射功能无法识别此属性,因此它永远不会像我希望的那样写入 CSV 文件的末尾。关于如何做到这一点有什么想法吗?是否必须手动写入CSV?请告诉我。谢谢!
编辑:我的列表>>由于某种原因,这里也返回为 null,因此它不会通过自动映射写入。
public class TemplateViewModelMap<TViewModel> : ClassMap<TViewModel> where TViewModel : class
{
public TemplateViewModelMap()
{
AutoMap(CultureInfo.InvariantCulture);
// Use Reflection to check property for complex object type to remove/ignore from ClassMap.
PropertyInfo[] properties = typeof(TViewModel).GetProperties();
foreach (PropertyInfo property in properties)
{
string fieldPropertyName = "Fields";
if (property.Name.Equals(fieldPropertyName) == true)
{
MemberReferenceMap item = ReferenceMaps.Find(property);
ReferenceMaps.Add(item);
}
}
}
I am currently trying to get my CSV Helper AutoMap class to write out column headers/values for a List<> property from my other Class. For some reason, the functionality for auto mapping doesn't recognize this property, so it never gets written to the end of my CSV file like I want it to. Any thoughts on how to do this? Does it have to be written to CSV manually? Please let me know. Thanks!
EDIT: My List<> also comes back as null for some reason here so it doesn't get written via auto mapping.
public class TemplateViewModelMap<TViewModel> : ClassMap<TViewModel> where TViewModel : class
{
public TemplateViewModelMap()
{
AutoMap(CultureInfo.InvariantCulture);
// Use Reflection to check property for complex object type to remove/ignore from ClassMap.
PropertyInfo[] properties = typeof(TViewModel).GetProperties();
foreach (PropertyInfo property in properties)
{
string fieldPropertyName = "Fields";
if (property.Name.Equals(fieldPropertyName) == true)
{
MemberReferenceMap item = ReferenceMaps.Find(property);
ReferenceMaps.Add(item);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在尝试映射一个具有字段但没有属性的类?在这种情况下,您可以将配置设置为
MemberTypes.Fields
。Are you trying to map a class that has fields and not properties? In that case you can set the configuration to
MemberTypes.Fields
.