i got a class which holds info about pictures, like filepath, hashvalue, bytes. in another class i got a generic list where i put objects from the class that holds picture info.
that class looks like this:
[Serializable()]
class PicInfo : ISerializable
{
public string fileName { get; set; }
public string completeFileName { get; set; }
public string filePath { get; set; }
public byte[] hashValue { get; set; }
public PicInfo()
{ }
public PicInfo(SerializationInfo info, StreamingContext ctxt)
{
this.fileName = (string)info.GetValue("fileName", typeof(string));
this.completeFileName = (string)info.GetValue("completeFileName", typeof(string));
this.filePath = (string)info.GetValue("filePath", typeof(string));
this.hashValue = (byte[])info.GetValue("hashValue", typeof(byte[]));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("fileName", this.fileName);
info.AddValue("completeFileName", this.completeFileName);
info.AddValue("filePath", this.filePath);
info.AddValue("hashValue", this.hashValue);
}
}
my list is just list<picinfo> pi = new list<picinfo>();
what would be the eaziest way to serialize this list?
If you want to use
BinaryFormatter
(which I really don't advise), you can use:If you want to use
XmlSerializer
(probably preferable IMO), but need thebyte[]
, then:Personally, I'd use protobuf-net:
Sizes:
BinaryFormatter
: 488 bytesXmlSerializer
: 251 bytes