Saving settings

  • Thread starter Thread starter timb
  • Start date Start date
T

timb

Hi,
is it possible to access the properties of a class or structure in a for
each statement?

I want to iterate through the stirng properties in my class or structure and
then write them away to the config file.

thanks for your help in advance
 
Try the following which will put all the string values from your objext into
an array "val".

Dim properties As System.ComponentModel.PropertyDescriptorCollection
properties = System.ComponentModel.TypeDescriptor.GetProperties _(myobject)
Dim pd as PropertyDescriptor
dim val() as string
dim i,n as integer
While i < properties.Count
pd = properties.Find(prop, True)
if pd.ProperType.Name = "String" then
val(n) = properties.Find(prop, True).GetValue(myObject)
n = n + 1
end if
i = i + 1
Wend
 
Do you mean XML Serialization or CLR Serialization?

I'm not sure I'd recommend CLR Serialization as a technique for saving
settings. What happens when you want to add new settings? Dealing with
versioning is possible but not straightforward. I tend to avoid this
approach if I think the serialized data is likely to outlive the class in
question. This tends to be the case with settings - they're going to be
persisted, and you're probably going to want them to continue to work when
thhe software is updated.

But I would use XML Serialization - it is reasonably robust in the face of
gradual changes to the data. (Of course if you completely revamp things and
change the names, it's going to be hard whatever you do...) It's also able
to produce files that are easier to edit by hand.
 
Back
Top