FileHelpers Master / Detail - Option Strict On禁止后期绑定

时间:2013-12-17 12:00:58

标签: vb.net filehelpers option-strict

我有一些问题要确定如何使用严格选项删除我使用FileHelpers时出现的错误。

我初始化了MasterDetails类

Private _res As MasterDetails()

调用MasterDetailEngine的函数

Private Function ReadCsvFile(ByVal fileName As String, ByVal tipodoc As String) As Boolean
engine = New MasterDetailEngine(GetType(CabecDocVgr), GetType(LinhasDocVgr), CommonSelector.MasterIfContains,
                                            "@")
            _res = engine.ReadFile(strStartPath)
Return true
End Function

这是主人的课程:

<DelimitedRecord(";")>
Public NotInheritable Class CabecDocVgr
    Public TipoLinha As String
    Public Doc As String
    Public Entidade As String
    Public DataDoc As String
    Public RefDoc As String
End Class

这一个,详情:

<DelimitedRecord(";")> _
Public NotInheritable Class LinhasDocVgr
    Public Tipolinha As String
    Public Artigo As String
    Public Armazem As String
    Public Localizacao As String
    Public Lote As String
    Public Qtd As Integer
    Public UniMedida As String
    Public DataValidade As String
End Class

每个主/细节都是创建一个带有标题和相关行的新文档。

当我调用Master或Details类的成员时,我可举一个出现错误的例子:

Private Function TransformaDocF(ByVal tipoDoc As String) As Boolean

    For numdoc As Integer = 0 To _res.Length - 1

        Dim documentosOrigem(0) As Object
        Dim docOrigem As New GcpBEDocumentoCompra
        Dim docDestino As New GcpBEDocumentoCompra

        Dim query As String = String.Format("SELECT TOP 1 NumDoc FROM cabecdoc WHERE RefDocOrig='{0}'",
                                            _res(numdoc).Master.doc)

        Dim lista As New StdBELista()   
        lista = Motor.Consulta(query)

        If Not lista.Vazia Then
            If Not lista.NoInicio And Not lista.NoFim Then
                Dim numeroDoc As Integer = CInt(lista.Valor("NumDoc"))
                'bExecuta = True
            End If
        End If

        docOrigem = Motor.Comercial.Compras.Edita("000", "VGR", "2013", _res(numdoc).Master.doc)
        documentosOrigem(0) = docOrigem

        docDestino.TipoEntidade = "F"
        docDestino.Serie = "2013"
        docDestino.Entidade = docOrigem.Entidade.TrimStart(CChar("0"))
        'DocDestino.DataDoc = "01-01-2013"
        docDestino.Tipodoc = "VFA"
        docDestino.RefDocOrig = _res(numdoc).Master.refDoc

        Try
            If docOrigem.Linhas.NumItens > 0 Then
                For numlinha As Integer = 0 To _res(numdoc).Details.Length - 1
                    If docOrigem.Linhas(numlinha + 1).Artigo = _res(numdoc).Details(numlinha).Artigo Then
                        docOrigem.Linhas(numlinha + 1).Quantidade = docOrigem.Linhas(numlinha + 1).QuantSatisfeita +
                                                                    _res(numdoc).Details(numlinha).Qtd
                    End If
                Next
            End If
            Motor.Comercial.Vendas.TransformaDocumentoEX2(documentosOrigem, CType(docDestino, GcpBEDocumentoVenda), True)
            Return True
        Catch ex As Exception

            MessageBox.Show(ex.Message)
            Return False
        End Try

    Next
    Return True
End Function

例如,调用_res(numdoc).Master.refDoc会给我一个错误:“Option Strict On禁止后期绑定”

关于我需要修改什么的任何想法,以便错误可以消失?

谢谢

1 个答案:

答案 0 :(得分:1)

尝试使用泛型。我不是很擅长VB.NET,但我觉得它应该是这样的:

'declare _res as an array of MasterDetails<CabecDocVgr, LinhasDocVgr>
Dim _res As MasterDetails(Of CabecDocVgr, LinhasDocVgr)()

'instantiate the generic version of the FileHelpers engine
Dim engine = New MasterDetailEngine(Of CabecDocVgr, LinhasDocVgr)(CommonSelector.MasterIfContains, "@")

'should not cause 'late binding error' since the results are strongly typed
_res = engine.ReadFile("")