I must implement a web service which expose a list of values (integers, custom classes etc).
My working solution returns a List<T>
, and according to FxCop it is better to return a Collection<T>
or ReadOnlyCollection<T>
.
If I choose to return a ReadOnlyCollection<T>
, the web service shows an error like:
To be XML serializable, types which inherit from
ICollection
must have an implementation ofAdd(System.Int32)
at all levels of their inheritance hierarchy.System.Collections.ObjectModel.ReadOnlyCollection
1
[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
does not implementAdd(System.Int32)
.
What is your favorite way to use internally a List<T>
and expose a Collection<T>
? (using C#, and preferably framework 2.0 only)