473,569 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with serializing multiple collections with a base class

I have the following code. When I serialize the DriverCollectio n I would
like to get both the Driver Collection and the DeletedItems collection. I
end up with only the Driver collection. I have tried numerous attributes
with no success. Any help would be appreciated...
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Seri alization;
using System.Runtime. Serialization;
using System.Runtime. Serialization.F ormatters.Binar y;
using System.Collecti ons;

namespace SerialTest
{
#region BusinessObjectB ase
/// Summary description for BusinessObjectB ase.
/// </summary>
[Serializable()]
public abstract class BusinessObjectB ase
{
public BusinessObjectB ase()
{}
}
#endregion //BusinessObjectB ase

#region BusinessObjectC ollectionBase
/// <summary>
/// Summary description for BusinessObjectC ollectionBase.
/// </summary>
[Serializable()]
public class BusinessObjectC ollectionBase : CollectionBase
{
public DeletedItemColl ection _deletedItems = new DeletedItemColl ection();

public BusinessObjectC ollectionBase()
{}

public DeletedItemColl ection DeletedItems
{
get{return _deletedItems;}
set{_deletedIte ms = value;}
}
}
#endregion //BusinessObjectC ollectionBase

#region DeletedItemColl ection
/// <summary>
/// Summary description for BusinessObjectC ollectionBase.
/// </summary>
[Serializable()]
public class DeletedItemColl ection : CollectionBase
{
#region Constructors

public DeletedItemColl ection()
{}

#endregion

public BusinessObjectB ase this[int index]
{
get{return (BusinessObject Base)List[index];}
set{List[index] = value;}
}

public int Add(BusinessObj ectBase value)
{
return List.Add(value) ;
}

}
#endregion //DeletedItemColl ection

#region DriverCollectio n
/// <summary>
/// Summary description for DriverCollectio n.
/// </summary>
[Serializable()]
public class DriverCollectio n : BusinessObjectC ollectionBase
{
#region Constructors

public DriverCollectio n()
{}

#endregion

#region IListMethods

public Driver this[int index]
{
get{return (Driver)List[index];}
set{List[index] = value;}
}

public int Add(Driver value)
{
return List.Add(value) ;
}

public bool Contains(Driver value)
{
return List.Contains(v alue);
}

public bool Contains(int driverNumber)
{
Driver d = GetDriver(drive rNumber);
return d == null ? false : Contains(d);
}

public bool ContainsDeleted (int driverNumber)
{
foreach(Busines sObjectBase bob in _deletedItems)
{
Driver d = (Driver)bob;
if(d.Number == driverNumber)
return true;
}

return false;
}

public int IndexOf(Driver value)
{
return List.IndexOf(va lue);
}

public int IndexOf(int driverNumber)
{
Driver d = GetDriver(drive rNumber);
return d == null ? -1 : IndexOf(d);
}

public void Remove(Driver value)
{
List.Remove(val ue);
}

public Driver GetDriver(int driverNumber)
{
for(int i = 0; i < this.Count; i++)
if(this[i].Number == driverNumber)
return this[i];

return null;
}

public void DeleteDriver(in t driverNumber)
{
Driver d = GetDriver(drive rNumber);
Remove(d);
_deletedItems.A dd(d);
}

#endregion
}
#endregion //DriverCollectio n

#region Driver
/// <summary>
/// Summary description for Driver.
/// </summary>
[Serializable()]
public class Driver : BusinessObjectB ase
{
#region Constructors

public Driver()
{
}

#endregion
#region Number

int _number = 0;
public int Number
{
get{return _number;}
set
{
if(value != _number)
{
_number = value;
}
}
}

#endregion

}
#endregion //Driver

/// <summary>
/// Summary description for Class1.
/// </summary>
class Tester
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
DriverCollectio n drivers = new DriverCollectio n();
Driver driver1 = new Driver();
Driver driver2 = new Driver();
Driver driver3 = new Driver();
Driver driver4 = new Driver();
driver1.Number = 1;
drivers.Add(dri ver1);
driver2.Number = 2;
drivers.Add(dri ver2);
driver3.Number = 3;
drivers.Add(dri ver3);
driver4.Number = 4;
drivers.Add(dri ver4);

drivers.DeleteD river(2);
drivers.DeleteD river(3);

//*************** *************
// XML serialization
//*************** *************
// Creat a Serializer
try
{

XmlSerializer serializer = new XmlSerializer(t ypeof(DriverCol lection));

// Create an XmlTextWriter using a FileStream.
Stream fs = new FileStream(@"C: \NewPolicy.xml" , FileMode.Create );
XmlWriter writer =
new XmlTextWriter(f s, Encoding.Unicod e);

// Serialize using the XmlTextWriter.
serializer.Seri alize(writer, drivers);
writer.Close();
}
catch (System.Excepti on e)
{
throw e;
//Handle exception here
}
}
}
}

--
Gonzo
Nov 12 '05 #1
0 1844

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

Similar topics

4
353
by: Angelos Karantzalis | last post by:
Hi guys. I've come across a problem when I tried to serialize a class into xml, only to discover that the parent class's XML Serialization properties weren't included in the output xml. Actually, the class I'm serializing is two steps down in the inheritance ladder. It's got a parent class which also has a parent class :( All those classes...
0
1477
by: okinrus | last post by:
Can someone take a look at this code and figure out why Serializable_base::add_serializer throws std::bad_alloc. The problem seems to be the compiler because msvc++ 7.1 says c:\LibSerial\LibSerial.cpp(83) : warning C4584: 'serial::E' : base-class 'serial::A' is already a base-class of 'serial::C' c:\LibSerial\LibSerial.cpp(10) : see...
0
298
by: Gonzo | last post by:
I have the following code. When I serialize the DriverCollection I would like to get both the Driver Collection and the DeletedItems collection. I end up with only the Driver collection. I have tried numerous attributes with no success. Any help would be appreciated... using System; using System.IO; using System.Text; using...
0
2478
by: big A | last post by:
I am receiving an error stating that File or Assembly name <filname.dll>, or one of its dependencies, was not found In one assembly I have three abstract classes In another I have three derived classes from the abstract classes The 1st class contains the 2nd class The 2nd class is a custom collection for the 3rd class
1
2411
by: jeff | last post by:
I am using .NET remoting with a class,call it MyClass, that contains many other classes (say one of them is MySubClass). I have been able to successfully call functions from the MyClass, but when I try to access the sub-classes it gives me a: System.Runtime.Serialization.SerializationException "The constructor to deserialze an object of type...
4
7004
by: Mark Sizer | last post by:
Hi people, I'm having trouble trying to achieve something in C# and win forms, and am looking for a little advice if anyone has a moment. I've got two classes: 1) a base class 2) a derived class that inherits from it
0
1399
by: Kenneth Baltrinic | last post by:
Is the following code correct for serializing a quasi-single class, that is a class that has a descreet (though more than one, so not a true singleton) number of static instances and no dynamically creatable instances? Please forgive my use of terms. Quasi-signleton is a term I made up and static instances is a little bogus too but I don't...
0
2485
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem serializing the object but there seems to be a problem serializing an array of objects. Any help will be appreciated "Cannot assign object of type...
0
1441
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...
1
1244
by: Karthik1979 | last post by:
I have a custom class inherited from List<T> collection. Along with the base class functionality, I have included my additional properties. When serializing, only the base class items are serialized not my additional properties. I have designed a business object collection like this and I have to pass it across the service layer. But in...
0
7700
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...
0
7924
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. ...
0
8125
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...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
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...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
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...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.