Vb.net net,实例化一个类

Vb.net net,实例化一个类,vb.net,Vb.net,我在为已定义的类成员赋值时遇到问题。OutgoingInvoicesData和OutgoingInvoicesDataHeader类是从XML自动创建的,可通过Intellisense访问。 那么,我在这里遗漏了什么,或者我做错了什么,我如何实例化一个类并将值分配给它的成员而不出错,以便序列化和反序列化它的数据 Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

我在为已定义的类成员赋值时遇到问题。OutgoingInvoicesData和OutgoingInvoicesDataHeader类是从XML自动创建的,可通过Intellisense访问。
那么,我在这里遗漏了什么,或者我做错了什么,我如何实例化一个类并将值分配给它的成员而不出错,以便序列化和反序列化它的数据

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    Dim oid As OutgoingInvoicesData = New OutgoingInvoicesData()
    oid.Header.SupplierID = 26742352147 'Here: Object reference not set to an instance of an object.
    oid.Header.InvoiceType = 1
End Sub
End Class

<System.SerializableAttribute()>
<System.ComponentModel.DesignerCategoryAttribute("code")>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://mypage/OutgoingInvoicesData/v3.2")> 
<System.Xml.Serialization.XmlRootAttribute([Namespace]:= "http://mypage/OutgoingInvoicesData/v3.2", IsNullable:=False)>
Partial Public Class OutgoingInvoicesData
Private headerField As OutgoingInvoicesDataHeader

Public Property Header As OutgoingInvoicesDataHeader
    Get
        Return Me.headerField
    End Get
    Set(ByVal value As OutgoingInvoicesDataHeader)
        Me.headerField = value
    End Set
End Property
End Class

<System.SerializableAttribute()>
<System.ComponentModel.DesignerCategoryAttribute("code")>
<System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="http://mypage/OutgoingInvoicesData/v3.2")>
Partial Public Class OutgoingInvoicesDataHeader
Private supplierIDField As ULong
Private invoiceTypeField As Byte

Public Property SupplierID As ULong
    Get
        Return Me.supplierIDField
    End Get
    Set(ByVal value As ULong)
        Me.supplierIDField = value
    End Set
End Property

Public Property InvoiceType As Byte
    Get
        Return Me.invoiceTypeField
    End Get
    Set(ByVal value As Byte)
        Me.invoiceTypeField = value
    End Set
End Property
End Class
公共类表单1
私有子表单1_Load(发送方作为对象,e作为事件参数)处理Me.Load
作为OutgoingInvoicesData的Dim oid=新的OutgoingInvoicesData()
oid.Header.SupplierID=26742352147'此处:对象引用未设置为对象的实例。
oid.Header.InvoiceType=1
端接头
末级
部分公共类支出发票数据
专用标题字段作为OutgoingInvoicesDataHeader
公共属性标头作为OutgoingInvoicesDataHeader
收到
还我,海德菲尔德
结束
设置(ByVal值作为OutgoingInvoicesDataHeader)
Me.headerField=值
端集
端属性
末级
部分公共类OutgoingInvoicesDataHeader
私人供应商字段为ULong
私有invoiceTypeField作为字节
公共财产供应商为ULong
收到
把我还给我,供应商菲尔德
结束
设置(ByVal值为ULong)
Me.supplierIDField=值
端集
端属性
公共属性InvoiceType作为字节
收到
Return Me.invoiceTypeField
结束
设置(ByVal值作为字节)
Me.invoiceTypeField=值
端集
端属性
末级

初始化类时,属性“Header”为空,因此不能为其“SupplierID”赋值

改变

Private headerField As OutgoingInvoicesDataHeader


那很有效,谢谢。这里有没有“将xml粘贴为类”这样自动执行的方法?我不知道,抱歉。但是通过adwancing,我得到了另一种情况,例如:Private uBLExtensionsField作为UBLExtensionsUBLExtension(),它是数组,不接受关键字New,比如:Private uBLExtensionsField作为New UBLExtensionsUBLExtension()。在这里做什么?在这里做什么?学习基础知识!数组也可以用new构造,但之后不能更改其大小(尽管可以重新定尺寸,从而在内部复制数组元素)。但是您可能已经从反序列化中获得了一个数组,只需将其赋值(否则语法将是
私有uBLExtensionsField(-1)作为UBLExtensionsUBLExtension
)。谢谢Cristoph。我还做什么来学习基础知识?如果我知道-我不会问!是的,我从反序列化中得到一个数组,该数组在sise中可能会有所不同,这取决于相同类型的其他文档。如果我们不知道数组的大小,如何定义?
Private headerField As New OutgoingInvoicesDataHeader