Hello timb,
MyClass c = new MyClass();
// init c here
foreach (PropertyInfo pi in c.GetType().GetProperties())
{
object o = pi.GetValue(c, null);
// do something here...
}
--
Matt Berther
http://www.mattberther.com
> Hi,
> is it possible to access the properties of a class or structure in
[quoted text clipped - 4 lines]
>
> thanks for your help in advance
Try Serializing the class and storing it away. This is much easier that doing
it all by yourself.
Rgds,
Anand M
VB.NET MVP
http://www.dotnetindia.com
> Hi,
> is it possible to access the properties of a class or structure in a for
[quoted text clipped - 4 lines]
>
> thanks for your help in advance
Dennis - 30 Nov 2004 00:25 GMT
> Try Serializing the class and storing it away. This is much easier that doing
> it all by yourself.
[quoted text clipped - 12 lines]
> >
> > thanks for your help in advance
Dennis - 30 Nov 2004 00:33 GMT
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
> Try Serializing the class and storing it away. This is much easier that doing
> it all by yourself.
[quoted text clipped - 12 lines]
> >
> > thanks for your help in advance
Ian Griffiths [C# MVP] - 30 Nov 2004 08:33 GMT
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.

Signature
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/
> Try Serializing the class and storing it away. This is much easier that
> doing
[quoted text clipped - 8 lines]
>> and
>> then write them away to the config file.