标记为Deliminted但是错误的类不是

问题描述 投票:0回答:1

我有一个可疑的任务,即升级使用文件助手的旧vb应用程序,但出于某种原因,它似乎忽略了我将其标记为分隔记录的事实。

在表单中,它使用以下内容将csv文件附加到记录中,该记录与c#如何相同。

Private Sub browseButton_Click(sender As System.Object, e As System.EventArgs) _
    Handles browseButton.Click

    Try
        Dim file = GetFile()
        '' Errors
        Dim errors As New Dictionary(Of Integer, String)

        If IO.File.Exists(file) Then
            Dim engine As New FileHelperEngine(Of AveryOrderCsv)
            _records = CType(engine.ReadFile(file), AveryOrderCsv()).ToList()

            Dim count As Integer = 0
            Dim success As Integer = 0

            For Each averyOrderCsv As AveryOrderCsv In _records
                Try
                    ImportProgressBar.Value = count
                    ImportProgressLabel.Text = String.Format("Importing {0} of {1} dockets",
                        count + 1, _records.Count())
                    System.Windows.Forms.Application.DoEvents()

                    If CreateSop(averyOrderCsv) Then
                        success = success + 1
                    End If
                Catch ex As Exception
                    errors.Add(count, ex.Message)
                End Try
                count = count + 1
            Next
        End If
    Catch ex As Exception
        ExceptionManager.HandleUnexpectedException(ex)
    End Try

班级

Imports AveryIntegration.Common.CSV
Imports FileHelpers
Imports System
Imports System.Diagnostics

Namespace AveryIntegration.Common.CSV.Records
    <DelimitedRecord(",")>
    Public Class AveryOrderCsv
        <FieldConverter(GetType(CustomStringConvertor))>
        <FieldQuoted>
        Public String2 As String

        <FieldConverter(GetType(CustomStringConvertor))>
        <FieldQuoted>
        Public String3 As String

        <FieldConverter(GetType(CustomStringConvertor))>
        <FieldQuoted>
        Public String4 As String

        <FieldConverter(GetType(CustomStringConvertor))>
        <FieldQuoted>
        Public String5 As String

        <FieldConverter(GetType(CustomStringConvertor))>
        <FieldQuoted>
        Public String10 As String

        <FieldConverter(GetType(CustomStringConvertor))>
        <FieldQuoted>
        Public String15 As String

        Public Decimal1 As Decimal

        Public Decimal5 As Decimal

        Public Decimal8 As Decimal

        Public Decimal9 As Decimal

        Public Decimal10 As Decimal

        Public Date1 As DateTime

        Public Ticket2 As Integer

        <DebuggerNonUserCode>
        Public Sub New()
            MyBase.New()
        End Sub
    End Class
End Namespace

我得到的错误如下,但正如您从上面看到的,我已将其声明为分隔记录并导入导入FileHelpers

enter image description here

vb.net filehelpers
1个回答
1
投票

在VB中,属性必须位于同一逻辑行上。

<DelimitedRecord(",")> Public Class AveryOrderCsv

要么

<DelimitedRecord(",")> _
Public Class AveryOrderCsv

属性也一样。

文章Applying Attributes说:

在Visual Basic中,属性由尖括号括起,并且必须位于同一逻辑行上;如果需要换行符,可以使用行继续符。

© www.soinside.com 2019 - 2024. All rights reserved.