I'm trying to set the date format of a CSV file I'm reading from via the FieldConverter attribute but I'm receiving the following error -
我正在尝试通过FieldConverter属性设置我正在读取的CSV文件的日期格式,但我收到以下错误 -
Attribute 'FieldConverter' is not valid on this declaration type. It is only valid on 'field' declarations.
属性“FieldConverter”在此声明类型上无效。它仅对“字段”声明有效。
Any idea why this is happening and how I can fix it?
知道为什么会发生这种情况以及如何解决这个问题吗?
[DelimitedRecord(",")]
[IgnoreFirst(1)]
public class SomeViewModel
{
public int account { get; set; }
[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime doc_dte { get; set; }
}
1 个解决方案
#1
12
As you can see in the error message you can't use attribute FieldConverter
on property, only on field. So, just change your property to a field:
正如您在错误消息中看到的那样,您不能在属性上使用属性FieldConverter,仅在字段上使用。所以,只需将您的属性更改为字段:
[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime doc_dte;
#1
12
As you can see in the error message you can't use attribute FieldConverter
on property, only on field. So, just change your property to a field:
正如您在错误消息中看到的那样,您不能在属性上使用属性FieldConverter,仅在字段上使用。所以,只需将您的属性更改为字段:
[FieldConverter(ConverterKind.Date, "dd-MM-yyyy")]
public DateTime doc_dte;