Cannot serialize this List<T> extension
- by Jaxidian
I'm trying to push a subset of a collection of data through WCF to be consumed by WCF - think paged data. As such, I want this collection to have one page's worth of data as well as a total number of results. I figured this should be trivial by creating a custom object that extends List. However, everything I do results in my TotalNumber property coming across as 0. All of the data gets serialized/deserialized just fine but that single integer won't come across at all.
Here's my first attempt that failed:
[Serializable]
public class PartialList<T> : List<T>
{
public PartialList()
{
}
public PartialList(IEnumerable<T> collection)
: base(collection)
{
}
[DataMember]
public int UnpartialTotalCount { get; set; }
And here's my second attempt that failed in the exact same way:
[Serializable]
public class PartialList<T> : List<T>, ISerializable
{
public PartialList()
{
}
public PartialList(IEnumerable<T> collection)
: base(collection)
{
}
[DataMember]
public int UnpartialTotalCount { get; set; }
protected PartialList(SerializationInfo info, StreamingContext context)
{
UnpartialTotalCount = info.GetInt32("UnpartialTotalCount");
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("UnpartialTotalCount", UnpartialTotalCount);
}
}
What's the deal here??