473,396 Members | 2,002 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,396 software developers and data experts.

Serialization of an inherited BindingList<T>

I posted this to the xml group but got no responses, so I thought I'd
try here.

I have the following small class which inherits from the generic List
class:

[Serializable, XmlRoot("FoodItemList")]
public class FoodItemList : BindingList<FoodItem>
{
private bool _hasChanges = false;
[XmlAttribute("HasChanges")]
public bool HasChanges
{
get { return _hasChanges; }
set { _hasChanges = value; }
}

private DateTime _lastUpdated = DateTime.MinValue;
[XmlAttribute("LastUpdated")]
public DateTime LastUpdated
{
get { return _lastUpdated; }
set { _lastUpdated = value; }
}
}

Basically, I wanted to add a couple of properties and have them be
serialized as attributes with the class. Here is the xml that is
produced:

<?xml version="1.0" encoding="utf-8"?>
<FoodItemList>
<FoodItem Description="This is the description" UnitPrice="1.85"
SoldByWeight="false" ItemType="Entree" ItemMeal="Both" Id="1234" />
</FoodItemList>

Here is the code I use to serialize them:

private void btnSave_Click(object sender, EventArgs e)
{
FoodItemList foods = new FoodItemList();

FoodItem fi = new FoodItem();

fi.Id = 1234;
fi.Description = "This is the description";
fi.ItemMeal = FoodItemMeal.Both;
fi.ItemType = FoodItemType.Entree;
fi.SoldByWeight = false;
fi.UnitPrice = 1.85m;

foods.Add(fi);
foods.HasChanges = false;
foods.LastUpdated = DateTime.Now;

StreamWriter sw = new StreamWriter(@"c:\testser.xml");
XmlSerializer xs = new XmlSerializer(typeof(FoodItemList));

XmlSerializerNamespaces xsn = new
XmlSerializerNamespaces();
xsn.Add("", "");

xs.Serialize(sw, foods, xsn);

sw.Close();
}

My two added properties are not serialized. Not as properties nor as
elements. How can I get them to serialize?

Thanks,

Chris

Apr 7 '06 #1
0 1503

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

Similar topics

4
by: hazz | last post by:
The data access layer below returns, well, a mess as you can see on the last line of this posting. What is the best way to return customer objects via a datareader from the data layer into my view...
5
by: Mike Surcouf | last post by:
Hi All I have a stored procedure wrapper that returns Collection<T>. The wrapper is generated by codesmith so I don't really want to start altering it. I need to use this collection in a...
4
by: Michel Walsh | last post by:
Hi, A datagrid has its DataSource set to a BindingList<CustomClass>. While the ListChanged event fires AFTER a deletion, I am looking for a simple way to be notified BEFORE the item would be...
2
by: csharpula csharp | last post by:
Hello, I would like to know what is better for data binding and serialization purposes ArrayList or List<? Thank you! *** Sent via Developersdex http://www.developersdex.com ***
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.