C
Christy Davids
OK, I confess. I'm really a Palm OS developer. I just
play a .NET developer on TV.
My problem is to programmatically create a resource with a
string list, which needs to be readable and writable.
I've been using code like this to do the reading:
Dim reader As ResXResourceReader = New ResXResourceReader
(SYS_STRINGS_FILEPATH)
Dim entry As DictionaryEntry
For Each entry In reader
tempResArray(resNum, 0) = entry.Key.ToString()
tempResArray(resNum, 1) = entry.Value.ToString()
resNum += 1
Next
reader.Close()
I get an "Object reference not set to an instance of an
object" error at entry.Key.ToString() in the first pass
through the For loop.
Stepping back to what I'm trying to do just a bit, the
reason for populating the array from the
ResXResourceReader is because when I try to add a string
to the resource list it seems to overwrite any strings
already in the file. So I am reading first, then writing
the original entries back out with a ResXResourceWriter.
Something like this:
Dim rw As ResXResourceWriter = New ResXResourceWriter
(SYS_STRINGS_FILEPATH)
resName = "System" & resNum
For i = 0 To resNum - 1
rw.AddResource(tempResArray(i, 0), tempResArray(i, 1))
Next
rw.AddResource(resName, dirName)
rw.Close()
rw.Dispose()
Is this really how you have to do it? It seems like there
must be a better approach. For example, what if I wanted
to delete a string from the list? I notice there's no
DeleteResource method for ResourceWriter or
ResXResourceWriter. All I'm trying to do is maintain and
access a simple list of strings at runtime.
TIA!
Christy
play a .NET developer on TV.
My problem is to programmatically create a resource with a
string list, which needs to be readable and writable.
I've been using code like this to do the reading:
Dim reader As ResXResourceReader = New ResXResourceReader
(SYS_STRINGS_FILEPATH)
Dim entry As DictionaryEntry
For Each entry In reader
tempResArray(resNum, 0) = entry.Key.ToString()
tempResArray(resNum, 1) = entry.Value.ToString()
resNum += 1
Next
reader.Close()
I get an "Object reference not set to an instance of an
object" error at entry.Key.ToString() in the first pass
through the For loop.
Stepping back to what I'm trying to do just a bit, the
reason for populating the array from the
ResXResourceReader is because when I try to add a string
to the resource list it seems to overwrite any strings
already in the file. So I am reading first, then writing
the original entries back out with a ResXResourceWriter.
Something like this:
Dim rw As ResXResourceWriter = New ResXResourceWriter
(SYS_STRINGS_FILEPATH)
resName = "System" & resNum
For i = 0 To resNum - 1
rw.AddResource(tempResArray(i, 0), tempResArray(i, 1))
Next
rw.AddResource(resName, dirName)
rw.Close()
rw.Dispose()
Is this really how you have to do it? It seems like there
must be a better approach. For example, what if I wanted
to delete a string from the list? I notice there's no
DeleteResource method for ResourceWriter or
ResXResourceWriter. All I'm trying to do is maintain and
access a simple list of strings at runtime.
TIA!
Christy