D
Dale Atkin
Still trying to come to grips with all the new features .NET gives me
(migrating from VB6), and I'm feeling like a real newbie here. I'm sure
there is an easy way to do this, but for some reason the 'obvious' solution
isn't working.
What I want to do, is create a list of a particular class, one for each of
the contents in a directory.
The code I'm using is as follows:
Private Sub LoadLocalFeatures(ByRef localFeatures As List(Of
clsFeature))
Dim ftrPath As New
IO.DirectoryInfo(IO.Path.Combine(GetApplicationDataDirectory, "ftrs\"))
Dim ftrFiles() As IO.FileInfo
Dim ftr As clsFeature
ftrFiles = ftrPath.GetFiles("FTR*.xml")
For i = 0 To UBound(ftrFiles)
ftr = New clsFeature
ftr.file = ftrFiles(i)
LoadFeature(ftr)
localFeatures.Add(ftr)
Next
End Sub
Now, I would have thought that by declaring ftr = New clsFeature, that it
would create a new instance of the feature class, that would be
manipulatable seperately from the old instance. The problem is, as soon as I
try to change the new instance, the old one updates as well. (as soon as I
hit the line ftr.file = ftrFiles(i), all of the members of the list get
updated with the new value)
For the life of me, I can't figure out another way to tackle this problem. I
need an indeteriminate number of clsFeature objects, added to a list. The
weirdest thing is, I was sure this code was working this morning??
Any bright ideas?
Dale
Here is the property Let on file, just in case you see something weird in
there:
<XmlIgnore()> Private Shared _file As FileInfo
<XmlIgnore()> Public Property file() As FileInfo
Get
Return _file
End Get
Set(ByVal value As FileInfo)
_file = value
id = file.Name
End Set
End Property
(migrating from VB6), and I'm feeling like a real newbie here. I'm sure
there is an easy way to do this, but for some reason the 'obvious' solution
isn't working.
What I want to do, is create a list of a particular class, one for each of
the contents in a directory.
The code I'm using is as follows:
Private Sub LoadLocalFeatures(ByRef localFeatures As List(Of
clsFeature))
Dim ftrPath As New
IO.DirectoryInfo(IO.Path.Combine(GetApplicationDataDirectory, "ftrs\"))
Dim ftrFiles() As IO.FileInfo
Dim ftr As clsFeature
ftrFiles = ftrPath.GetFiles("FTR*.xml")
For i = 0 To UBound(ftrFiles)
ftr = New clsFeature
ftr.file = ftrFiles(i)
LoadFeature(ftr)
localFeatures.Add(ftr)
Next
End Sub
Now, I would have thought that by declaring ftr = New clsFeature, that it
would create a new instance of the feature class, that would be
manipulatable seperately from the old instance. The problem is, as soon as I
try to change the new instance, the old one updates as well. (as soon as I
hit the line ftr.file = ftrFiles(i), all of the members of the list get
updated with the new value)
For the life of me, I can't figure out another way to tackle this problem. I
need an indeteriminate number of clsFeature objects, added to a list. The
weirdest thing is, I was sure this code was working this morning??
Any bright ideas?
Dale
Here is the property Let on file, just in case you see something weird in
there:
<XmlIgnore()> Private Shared _file As FileInfo
<XmlIgnore()> Public Property file() As FileInfo
Get
Return _file
End Get
Set(ByVal value As FileInfo)
_file = value
id = file.Name
End Set
End Property