Click to See Complete Forum and Search --> : Deserializing a costum ListViewItem obj


FranciscoDias
January 15th, 2010, 04:08 AM
I have this class:


class Toy : ListViewItem
{
//costum attributes

//constructor (this has to be like this so it can deserialize)
public Toy(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

}


but then when I deserialize all my costum attributes are lost... What I'm I doing wrong?
Thank you very much (sorry for making so many questions o this foruns xD)

DutchGuy
January 15th, 2010, 07:21 AM
Be sure to also add the default constructor besides the constructor for the IDeserialization interface.

FranciscoDias
January 15th, 2010, 02:42 PM
ok I think I got it but I'm getting and error if I have a subclass parent with the toy



class Toy : ListViewItem, ISerializable
{
//something here
}

class Car : Toy , ISerializable
{
//something here
}

class Bike : Toy , ISerializable
{
//Something here
}



I've created the Iserializable methods getobjectdata(...)

when serializing a Toy it's okay... when serializing a Car or Bike, Exception error :S:S

FranciscoDias
January 15th, 2010, 02:56 PM
Even Better!! Is there a way to remove the Iserializable attribute from a parent class?? my big problem is that ListViewItem is ISerializable.... but I want to remove this!! Is this possible? please tell me that it is! lool XD

Arjay
January 15th, 2010, 04:05 PM
Try using the Serializable attribute


[Serializable]
class Toy : ListViewItem
{

}

FranciscoDias
January 15th, 2010, 07:17 PM
doesn't work...:S

Arjay
January 15th, 2010, 10:20 PM
You also need to put the appropriate xmlserialization attributes on the public properties of your class.

Btw, deriving from ListViewItem may not work because the ListViewItem itself may not be serializable.