Serialize List of objects as XML

J

Jarod

Hello,

I have a list of objects that I want to serialize as XML and save it as
user setting. The objects are of type of the following class.

[Serializable]
public class SourceFolder
{
public SourceFolder(string path, bool controlled, bool
includesSub)
{
this.path = path;
this.controlled = controlled;
this.includesSub = includesSub;
}

public string Path
{
get
{
return path;
}
set
{
path = value;
}
}

public bool Controlled
{
get
{
return controlled;
}
set
{
controlled = value;
}
}

public bool IncludesSub
{
get
{
return includesSub;
}
set
{
includesSub = value;
}
}

private string path;
private bool controlled;
private bool includesSub;
}

In my settings object, I have a property of type List<SourceFolder>
that I assign my object list before saving. Unfortunately, the only
output in the file user.config is the following:

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

When I add the attribute
SettingsSerializeAs(SettingsSerializeAs.Binary) to the settings
property, it works, but the list is serialized binary what I do not
want.

Visual Studio 2005 help states that .NET framework is able to serialize
lists of any object to XML stream. What am I doing wrong that it does
not work for me? When I use List<string> instead of List<SourceFolder>,
it works fine, but not with my class.


Regards, Jens
 
J

Jarod

Hello,

In the meantime I have solved the problem. I made a wrapper class
SourceFolderList which contains the List<SourceFolder>. Additionally I
had to assign the attribute XmlInclude(typeof(SourceFolder)) to this
class and now it works fine.


Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top