473,320 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to save custom collections using ApplicationSettingsBase?

I'm working with the example code found at
http://msdn2.microsoft.com/en-us/lib...se(VS.80).aspx.

I would like to implement application settings based on some custom types.
For example, let's say I have a collection of settings that I could represent
similar to this code:

[Serializable()]
public class MyItem
{
private int myValue;
public int MyValue
{
get { return myValue; }
set { myValue = value; }
}

public MyItem(int value)
{
myValue = value;
}
}
[Serializable()]
public class MyCollection
{
private List<MyItem> list = new List<MyItem>();

public void Add(MyItem newItem)
{
list.Add(newItem);
}

public List<MyItem> TheList
{
get { return list; }
set { list = value; }
}
}

Then, in my ApplicationSettingsBase-derived class, I could add this:

sealed class FormSettings : ApplicationSettingsBase
{
. . .

[UserScopedSetting()]
public MyCollection TestCollection
{
get { return (MyCollection)this["TestCollection"]; }
set { this["TestCollection"] = value; }
}
}

to load the settings, I could do something like this:
private void Form1_Load_1(object sender,
EventArgs e)
{
testCollection = frmSettings1.TestCollection;
if (testCollection == null)
{
testCollection = new MyCollection();
testCollection.Add(new MyItem(count++));
testCollection.Add(new MyItem(count++));
}

and to save the settings, I would do this:

private void Form1_FormClosing_1(object sender, FormClosingEventArgs e)
{
//Synchronize manual associations first.
frmSettings1.FormText = this.Text + '.';
testCollection.Add(new MyItem(count++));
frmSettings1.TestCollection = testCollection;
frmSettings1.Save();
}

What am I missing? This code only saves an empty element like this:

<setting name="TestCollection" serializeAs="Xml">
<value />
</setting>

Thanks.
Apr 6 '06 #1
5 16500
Hi Mountain,
What am I missing? This code only saves an empty
element like this:

<setting name="TestCollection" serializeAs="Xml">
<value />
</setting>


It appears the corresponding SettingsProvider cannot serialize your custom
type property to the disk file.

When the LocalFileSettingsProvider serializes the property to disk, it
first attempts to call the ConvertToString or ConvertFromString on the
type's associated TypeConverter. If this does not succeed, it uses XML
serialization instead.

I suggest you need to implement a TypeConverter to your custom type class,
please refer to the following MSDN2 documentation for the further
information:

How to: Implement a Type Converter
http://msdn2.microsoft.com/en-us/lib...e5(VS.80).aspx

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 7 '06 #2
I was hoping that deriving from ApplicationSettingsBase would simplify the
implementation of application configuration settings. If I am forced to
implement TypeConverters for the types I define, then using
ApplicationSettingsBase becomes just as much work as not using
ApplicationSettingsBase.

Is there not a way to make the XML serialization suffice for a config file?

How can I proceed without going thru the work to implement a TypeConverter?
If a TypeConverter is my only choice, I think the old .NET 1.1 way of doing
things is better than deriving from ApplicationSettingsBase. Am I right?

Thanks,
Mountain

P.S. Is there any documentation that mentions the need for a TypeConverter?
I did not see this in my searches related to ApplicationSettingsBase. Can you
provide me with a link? Thanks.

""Gary Chang[MSFT]"" wrote:
Hi Mountain,
What am I missing? This code only saves an empty
element like this:

<setting name="TestCollection" serializeAs="Xml">
<value />
</setting>


It appears the corresponding SettingsProvider cannot serialize your custom
type property to the disk file.

When the LocalFileSettingsProvider serializes the property to disk, it
first attempts to call the ConvertToString or ConvertFromString on the
type's associated TypeConverter. If this does not succeed, it uses XML
serialization instead.

I suggest you need to implement a TypeConverter to your custom type class,
please refer to the following MSDN2 documentation for the further
information:

How to: Implement a Type Converter
http://msdn2.microsoft.com/en-us/lib...e5(VS.80).aspx

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 7 '06 #3
Hi,
Is there not a way to make the XML serialization suffice
for a config file?

How can I proceed without going thru the work to
implement a TypeConverter?
It appears your custom type is somewhat complicated for XML serialization.
I suggest you refer to the example in the following MSDN document, you may
need to define your custom type as that:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlserializationxmlserializerclasstopic .asp

P.S. Is there any documentation that mentions the need for a

TypeConverter?

I suggest you can refer to the paragraph "Settings Serialization" in the
following MSDN2 documentation, it introduces the serialization actions when
using the LocalFileSettingsProvider:

Application Settings Architecture
http://msdn2.microsoft.com/en-us/lib...t1(VS.80).aspx
Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 10 '06 #4
Gary,
Thanks for your suggestions. So far, however, none of this has helped.
David

I thought the whole idea of the
""Gary Chang[MSFT]"" wrote:
Hi,
Is there not a way to make the XML serialization suffice
for a config file?

How can I proceed without going thru the work to
implement a TypeConverter?


It appears your custom type is somewhat complicated for XML serialization.
I suggest you refer to the example in the following MSDN document, you may
need to define your custom type as that:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemxmlserializationxmlserializerclasstopic .asp

P.S. Is there any documentation that mentions the need for a

TypeConverter?

I suggest you can refer to the paragraph "Settings Serialization" in the
following MSDN2 documentation, it introduces the serialization actions when
using the LocalFileSettingsProvider:

Application Settings Architecture
http://msdn2.microsoft.com/en-us/lib...t1(VS.80).aspx
Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 14 '06 #5
Hi David,

I am regret to know that sample doesn't help. It appears your custom type
is somewhat complicated to XML serialization.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Obiwan Jacobi | last post by:
Hi all, Has anyone tried to build a custom Config Section Handler yet in .NET 2.0? I see that a lot of new Configuration classes were added in 2.0. But what is the correct way to extend the...
41
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
0
by: Jordan Bowness | last post by:
I make a similar post in another newsgroup, but this example is simplified somewhat. I have a component (cmpMyComponent) with 2 properties. The 1st property is a string value (Description) and...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
4
by: John Dalberg | last post by:
I noticed the starterkits timetracker & issue tracker load data from a database into custom collections (arraylists) which bind to a datagrid. What are the advantages of using custom collections...
4
by: Martin Widmer | last post by:
Hi folks. I am using this collection class: Public Class ContentBlocksCollection Inherits DictionaryBase 'Object variables for attributes 'Attributes Default Public Property Item(ByVal...
4
by: Richard Lewis Haggard | last post by:
I have an application that can't use the registry to save various user options and application settings. My first thought was to simply use an application configuration file but this approach seems...
0
by: =?Utf-8?B?Qy4gSHVnaGVz?= | last post by:
Hello, I have a .net 2.0 application using a 'Settings.settings' configuration file to store application settings. The settings are modified at runtime and stored when the user exits the...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.