OpenNETCF's XMLSerializer does not work

G

Guest

Hi

I tried to serialize an object in CF.NEt using OpenNETCF.org's XmlSerializer
The follwoing is the contruct of my objec
-------------Start Complex object---------
public class Perso

public int Age
public string Description
public double Height
public Person(


Age =20
Description = "Good Looking"
Height = 11.5



-------------End Complex object---------

and the following is the piece of code I used for serializatio

-------------Start Serialization ---------
Person person = new Person()

OpenNETCF.Xml.Serialization.XmlSerializer serializer = new OpenNETCF.Xml.Serialization.XmlSerializer(typeof(Person))

using (FileStream stream = new FileStream("person.txt",FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)

serializer.Serialize(stream,person )

-------------End Serialization ---------

The following is the file that is generated. If you see that the object is no serialized with its public members. Can anybody tell why? or where am I going wrong

<?xml version="1.0" encoding="us-ascii" ?><Person />
 
A

Alex Yakhnin [MVP]

Change your class to use properties instead of public member types.

public class Person
{
private int age;

public int Age
{
get
{
return age;
}
set
{
age = value;
}
}

....
}
--
Alex Yakhnin .NET CF MVP
www.intelliprog.com | www.opennetcf.org

Gururaj said:
Hi,

I tried to serialize an object in CF.NEt using OpenNETCF.org's XmlSerializer.
The follwoing is the contruct of my object
-------------Start Complex object----------
public class Person
{
public int Age;
public string Description;
public double Height;
public Person()
{

Age =20;
Description = "Good Looking";
Height = 11.5;

}
}
-------------End Complex object----------


and the following is the piece of code I used for serialization

-------------Start Serialization ----------
Person person = new Person();

OpenNETCF.Xml.Serialization.XmlSerializer serializer = new OpenNETCF.Xml.Serialization.XmlSerializer(typeof(Person));

using (FileStream stream = new FileStream("person.txt",FileMode.Create,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
serializer.Serialize(stream,person );
}
-------------End Serialization ----------

The following is the file that is generated. If you see that the object is
no serialized with its public members. Can anybody tell why? or where am I
going wrong.
 
G

Guest

And what about a class like the following. Basically a class containing an array/arraylist


------------------------------------------------------------------------------------------------------------------
using System
using System.Collections
using OpenNETCF.Xml.Serialization
using System.Xml.Serialization

namespace com.PBSG.HH3.Entitie

/// <summary
/// Summary description for Person
/// </summary
//[Serializable
public class Person : Entit

[XmlAttribute
public int _Age
[XmlAttribute
public string _Description
[XmlAttribute
public double _Height
private ArrayList _wives
public Person(

_Age =20
_Description = "Good Looking"
_Height = 11.5



public void AddWife(Person p

if (_wives == null

_wives = new ArrayList()

_wives.Add(p)



public Person(int age, string desc, double ht

_Age =age
_Description = desc
_Height = ht


[XmlArrayItem("Wife", typeof(Person))
[XmlArray
public Array Wive

ge

Person[] wives = new Person[_wives.Count]
_wives.CopyTo(wives)
return wives





public string Descriptio

ge

return _Description
 

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