Properties.Settings; ArrayList and a custom object

  • Thread starter Thread starter eugenet
  • Start date Start date
E

eugenet

Hello,

I am writing a Windows Forms application using .NET Framework 2.0 and
Visual Studio 2005.

I would like to use Properties.Settings class to persist a collection
of custom objects. For that I am creating a setting called Connections
of type System.Collections.ArrayList using the Properties designer in
VS.

At run-time I populate an arraylist with instances of my class and then
I set the Connections property to this arraylist. Then, I execute the
Save command on the Settings.Default.

The Save command does not generate an error, but no settings are
persisted either.

Do I need to do something special with ArrayList and my class
(serialization, perhaps) in order for settings to be persisted
correctly?

Many thanks for your help!

Evgueni
 
Evgueni,

I have your same problem; have you found a solution or a reason why
this is not working?

Thank you,
Gabriele
 
Unfortunately, no. Nobody responded to this posting or to the
WindowsForms.net forum...
 
I haven't been able to find this information either. I'm using one of my
MSDN support incidents on it. I'll post what they come up with.
 
Hello Eugene.

I think I've figured this one out. I haven't tried it out on ArrayList but
it's worked for every Type I've tried it on, including Bitmaps and custom
types.

First of all, if your type is a custom type (like class MyFont : Font) then
you'll have to mark it as [Serializable] and implement ISerializable. I
think you also have to write a serializable constructor.

Then you mark your settings property with
[SettingsSerializeAs(SettingsSerializeAs.Binary)]. Settings of certain types
cannot be created in the designer. In that case you'll have to add a file
Settings.cs that extends your internal sealed partial class Settings.

Tony
(e-mail address removed)
 
Back
Top