When set up an object for serialization I do the following:
[Serializable]
public class ContentModel
{
public int ContentId { get; set; }
public string HeaderRendered { get; set; }
public ContentModel()
{
ContentId = 0;
HeaderRendered = string.Empty;
}
public ContentModel(SerializationInfo info, StreamingContext ctxt)
{
ContentId = (int)info.GetValue("ContentId", typeof(int));
HeaderRendered = (string)info.GetValue("HeaderRendered", typeof(string));
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("ContentId ", ContentId);
info.AddValue("HeaderRendered", HeaderRendered);
}
}
It's quite exhausting when there are lots of properties. Is there a simpler or less verbose way of doing this in C# 4.0?