C# Programming
05-04-2009, 02:12 AM
Hi,
I'm new to the world of .Net and C#. I need some help with serialization:
I'm trying to serialize an object to an XML file, this object has a nested class which I also want to serialize:
[Serializable]
public class NewOrder
{
//constructor
public NewOrder()
{
}
//Destructor
~NewOrder()
{
}
private string accountGroupfield;
private string accountNumberfield;
public string AccountGroup
{
get
{
return accountGroupfield;
}
set
{
accountGroupfield = value;
}
}
public string AccountNumber
{
get
{
return accountNumberfield;
}
set
{
accountNumberfield = value;
}
}
[Serializable]
public class CardDetail
{
private string cardFirstNamefield;
private string cardLastNamefield;
private string cardNumberfield;
public string CardFirstName
{
get
{
return cardFirstNamefield;
}
set
{
cardFirstNamefield = value;
}
}
public string CardLastName
{
get
{
return cardLastNamefield;
}
set
{
cardLastNamefield = value;
}
}
public string CardNumber
{
get
{
return cardNumberfield;
}
set
{
cardNumberfield = value;
}
}
}
I have a function to serialize the object but all I get in the Xml file is:
100
66302
I've been searching around the internet for days now, but I still havent managed to get the nested class output as a nested element within the XML.
Apologies for rambling, the output to the XML I'm looking for is as follows:
100
66302
George
Balden
6123 2222 4444 6666
I'm new to the world of .Net and C#. I need some help with serialization:
I'm trying to serialize an object to an XML file, this object has a nested class which I also want to serialize:
[Serializable]
public class NewOrder
{
//constructor
public NewOrder()
{
}
//Destructor
~NewOrder()
{
}
private string accountGroupfield;
private string accountNumberfield;
public string AccountGroup
{
get
{
return accountGroupfield;
}
set
{
accountGroupfield = value;
}
}
public string AccountNumber
{
get
{
return accountNumberfield;
}
set
{
accountNumberfield = value;
}
}
[Serializable]
public class CardDetail
{
private string cardFirstNamefield;
private string cardLastNamefield;
private string cardNumberfield;
public string CardFirstName
{
get
{
return cardFirstNamefield;
}
set
{
cardFirstNamefield = value;
}
}
public string CardLastName
{
get
{
return cardLastNamefield;
}
set
{
cardLastNamefield = value;
}
}
public string CardNumber
{
get
{
return cardNumberfield;
}
set
{
cardNumberfield = value;
}
}
}
I have a function to serialize the object but all I get in the Xml file is:
100
66302
I've been searching around the internet for days now, but I still havent managed to get the nested class output as a nested element within the XML.
Apologies for rambling, the output to the XML I'm looking for is as follows:
100
66302
George
Balden
6123 2222 4444 6666