CollectionDataContract - Inheritance

Topics: General Discussion Forum, July and December Releases Forum
Dec 21, 2007 at 9:05 PM
Edited Dec 21, 2007 at 9:06 PM

I have a CollectionDataContract inheriting from List<T>. Here is an example.

CollectionDataContract(Name = "{0}List")
public class PagedList<T> : IEnumerable<T>
private uint m_PageSize;
System.Runtime.Serialization.DataMemberAttribute(IsRequired = false, Name = "PageSize", Order = 0)
public uint PageSize
get { return m_PageSize; }
set { m_PageSize = value; }

private string m_PageInfo;
System.Runtime.Serialization.DataMemberAttribute(IsRequired = false, Name = "PageInfo", Order = 1)
public string PageInfo
get { return m_PageInfo; }
set { m_PageInfo = value; }

The proxy created for the class ("{0}List") does not contain the properties PageInfo and PageSize.

Thanks in avance.

Dec 24, 2007 at 2:09 PM
When you use the CollectionDataContractAttribute you are basically decalaring your collection type and not its members so you won't get serialized the data memmbers as yoy point out inyour example. Follow the intended usage specified in the above attribute link and have a separate DataContract or MessageContract that may include your data members.