Collections in System.Collections.Immutable are not serializable. This library provides serializable wrappers for the collections, which allow using them as-is, while efficiently serializing and deserializing them (when possible, using a Builder
).
[DataContract]
public class ImmutableData
{
[DataMember]
private readonly ImmutableListSerializable<int> _list = new ImmutableListSerializable<int>();
public ImmutableList<int> List
{
get => _list.Value;
private set => _list.Value = value;
}
public ImmutableData WithList(ImmutableList<int> list)
{
return new ImmutableData { List = list };
}
}