我不能肯定我在正确使用<dependency>
<groupId>apache-commons-lang</groupId>
<artifactId>apache-commons-lang</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/apache-
commons-lang.jar</systemPath>
</dependency>
。我对OOP还是很陌生,MSDN上的许多文档都假设我不了解行话。
我创建了类(Lists
和ItemData
)作为新项目创建应用程序的一部分。这两个类都具有许多其他属性,但是在此示例中已对其进行了简化。
Materials
使用ItemData类中的FamilyID将项目分组,并且每个包装变化都是一个包含其自己的属性集的新Material。
目标:
Public Class ItemData
Public FamilyID As String
Public Description As String
'Public Material As New Collection() -- using collection didnt give me access to the properties in the Material class.
Public Material as new List(of Material)
... (Other Properties)
End Class
Public Class Material
Public _MaterialID As String
Property MaterialID() As String
Get
Return _MaterialID
End Get
Set(ByVal value As String)
_MaterialID = value
End Set
End Property
... (Other Properties)
EndClass
在应用程序中,我创建了ItemData的实例,可以直接在ItemData类中为属性分配值,但是我不知道如何添加新的Material。
NewItem.FamilyID = "ITEM0001"
NewItem.Material(1).MaterialID = "ITEM000101"
NewItem.Material(1).UnitofMeasure = "CASE"
NewItem.Material(2).MaterialID = "ITEM000102"
NewItem.Material(2).UnitofMeasure = "BOX"
答案 0 :(得分:0)
您应该创建材料类的实例并进行设置,就像这样。
NewItem.Material.Add(New Material With {.MaterialID = "ITEM000101", .UnitofMeasure = "CASE"})
NewItem.Material.Add(New Material With {.MaterialID = "ITEM000102", .UnitofMeasure = "BOX"})
答案 1 :(得分:0)
我认为最好的选择是定义接受参数的构造函数,以填充Material
类中的字段,然后轻松创建对象并将其添加到列表中,如下所示:
Imports System
Module Program
Sub Main(args As String())
Dim newItem As New ItemData
newItem.Material.Add(New Material("ITEM000101", "CASE"))
' etc.
End Sub
End Module
Public Class ItemData
Public FamilyID As String
Public Description As String
Public Material As New List(Of Material)
End Class
Public Class Material
' All your code can be simplified
Public Property MaterialID As String
Public Property UnitofMeasure As String
Public Sub New(MaterialID As String, UnitofMeasure As String)
Me.MaterialID = MaterialID
Me.UnitofMeasure = UnitofMeasure
End Sub
End Class
此外,您需要设置属性Public
以便从“外部”访问它们。您应该阅读一些有关访问修饰符的信息。
答案 2 :(得分:-1)
您好尝试使用Array而不是collections, 除了似乎您忘记了变量的类型
将Material()设置为字符串
希望效果很好...