Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2007, 10:48 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default Generic List Serialisation with custom property

Hi All,
I am using a generic list to contain a list of "Zone" objects.
I also have a "ZoneConfiguration" object that is part of a header for all zones.
I have created a Zones generic list and added a publi serialisable property called ZOneConfiguration.
Now when I serialise Zones there is not a ZoneCOnfiguratin object included.

Is it possible to have public properties serialised as part of a generic list?

This is my Zones definitaion, the zone collection serializes fine it is just the ZoneConfigurations that does not.

Code:
public class Zones : List<Zone> 
    {
        public event OnZoneAdded ZoneAdded;
        public event OnZoneChanged ZoneChanged;
        public event OnZoneConfigurationChanged ZoneConfigurationChanged;

        private ZoneConfiguration zoneConfiguration = new ZoneConfiguration();
        public ZoneConfiguration ZoneConfiguration 
        {
            get{return zoneConfiguration;}
            set
            {
                zoneConfiguration = value;
                //Dont do anything if there isn't any change                    
                if (Utilities.Serialiser.Compare(this, zoneConfiguration, typeof(ZoneConfiguration))) { return; }
                //Change the ZoneConfiguraton
                resetConfiguration();
                if (ZoneConfigurationChanged != null) { ZoneConfigurationChanged(); }
            }
        }

        public new void Add(Zone item)
        {
            //See if we need to add or change
            for (int i = 0; i < Count; i++)
            {
                if (this[i].ZoneID == item.ZoneID)
                {
                    //Dont do anything if there isn't any change                    
                    if (Utilities.Serialiser.Compare(this[i], item, typeof(Zone))) { return; }

                    //Delete old area from totals
                    ZoneConfiguration.TotalArea -= this[i].ZoneArea;
                    if (this[i].DesignZone) { ZoneConfiguration.DesignArea -= this[i].ZoneArea; } 

                    //Change the item
                    this[i] = item;

                    //Add new area to totals
                    ZoneConfiguration.TotalArea += item.ZoneArea;
                    if (item.DesignZone) { ZoneConfiguration.DesignArea += item.ZoneArea; }

                    //Bubbble event
                    if (ZoneChanged != null) { ZoneChanged(item); }
                    return;
                }
            }
            //Add the new item
            base.Add(item);
            ZoneConfiguration.TotalArea += item.ZoneArea;
            if (item.DesignZone) { ZoneConfiguration.DesignArea += item.ZoneArea; }
            if (ZoneAdded != null) { ZoneAdded(item); }

        }
        private void resetConfiguration()
        {
            zoneConfiguration.TotalArea = 0;
            zoneConfiguration.DesignArea = 0;
            foreach (Zone z in this)
            {
                zoneConfiguration.TotalArea += z.ZoneArea;
                if (z.DesignZone) { zoneConfiguration.DesignArea += z.ZoneArea; }
            }
        }
    }


======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old April 23rd, 2007, 12:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Hmmmm, no response, I must not have been very clear.

I have a class called Zone and a collection called Zones.

I have implimented the collection as a generic list
public Zones:List<Zone>{}

There some other fields that I wish to store along with the collection such as a MinValue and MaxValue.

So My implimentation is something like
public Zones:List<Zone>
{
 pubic int MinValue;
 pubic int MaxValue;
}

So to my problem.

When I use Serialisation to construct an XML representation of Zones the Min and Max values are not shown, only the array of Zone elements.

Is this he correct behavior of Generic Lists or am I missing something?


======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Generic List bound to GridView klavastrius ASP.NET 2.0 Basics 0 April 21st, 2008 12:05 PM
Generic List error ferahl C# 2 October 30th, 2007 03:28 AM
generic List<T> Sort() shadowcodes C# 2005 2 February 15th, 2007 01:30 PM
paging a generic list trancehead ASP.NET 2.0 Professional 0 July 7th, 2006 03:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.