473,883 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to save custom collections using ApplicationSett ingsBase?

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(newIte m);
}

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

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

sealed class FormSettings : ApplicationSett ingsBase
{
. . .

[UserScopedSetti ng()]
public MyCollection TestCollection
{
get { return (MyCollection)t his["TestCollection "]; }
set { this["TestCollection "] = value; }
}
}

to load the settings, I could do something like this:
private void Form1_Load_1(ob ject sender,
EventArgs e)
{
testCollection = frmSettings1.Te stCollection;
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_FormClosi ng_1(object sender, FormClosingEven tArgs e)
{
//Synchronize manual associations first.
frmSettings1.Fo rmText = this.Text + '.';
testCollection. Add(new MyItem(count++) );
frmSettings1.Te stCollection = testCollection;
frmSettings1.Sa ve();
}

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

<setting name="TestColle ction" serializeAs="Xm l">
<value />
</setting>

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

<setting name="TestColle ction" serializeAs="Xm l">
<value />
</setting>


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

When the LocalFileSettin gsProvider serializes the property to disk, it
first attempts to call the ConvertToString or ConvertFromStri ng 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 ApplicationSett ingsBase would simplify the
implementation of application configuration settings. If I am forced to
implement TypeConverters for the types I define, then using
ApplicationSett ingsBase becomes just as much work as not using
ApplicationSett ingsBase.

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 ApplicationSett ingsBase. 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 ApplicationSett ingsBase. 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="TestColle ction" serializeAs="Xm l">
<value />
</setting>


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

When the LocalFileSettin gsProvider serializes the property to disk, it
first attempts to call the ConvertToString or ConvertFromStri ng 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/
frlrfsystemxmls erializationxml serializerclass topic.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 LocalFileSettin gsProvider:

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/
frlrfsystemxmls erializationxml serializerclass topic.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 LocalFileSettin gsProvider:

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
1300
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 mechanism? I have my custom config.xsd that I'd like to use. I saw some support for application settings (ApplicationSettingsBase) but that's just name-value pairs, my config is hierarchical. -- of course, I can always implement a 1.1...
41
3463
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
1457
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 the 2nd property is a strongly typed collection class (myCollectionProperty). The collection contains a simple class (myCustomClass) which has 1 text property (TextProperty).
6
2339
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 having to do a httpwebreqeust call.
4
2161
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 over simpler objects like datareaders or datatables? John Dalberg
4
6181
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 nDBKey As Long) As ContentBlock Get
4
2655
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 flawed. The app config file appears to be updated with values while the application is running but when the application closes, the file seems to get restored to a pristine state and the accumulated user options and application settings are...
0
2092
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 application. Occasionaly, this exception will occur when calling the Settings.Default.Save() method: Invalid high surrogate character (0xDE1C). A high surrogate character must
1
4396
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 grid doesn't show colloections i.e. if I have a List<Objectthen the Collection is shown but when I click on the "..." button next to it nothing comes up. If I say CustomPropertyGrid p = new CustomPropertyGrid(); p.SelectedObject = new...
0
9933
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11125
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7962
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4607
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4211
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.