我收集的方式,与集合protobuf网需求GetEnumerator
系列化与Add
对反序列化类型工作时。是否有使用IReadOnlyCollection <T>/IReadOnlyList <T>与protobuf网
对于没有Add
的类型,可以设置在反序列化之前执行的继承类型。这适用于例如用IEnumerable
和List
:
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public class Sheep
{
public IEnumerable<string> Children { get; set; }
public Sheep()
{
Children = new List<string>();
}
}
var dolly = RuntimeTypeModel.Default.DeepClone(new Sheep
{
Children = new[]
{
"Bonnie",
"Sally",
"Rosie",
"Lucy",
"Darcy",
"Cotton"
}
});
然而,当我做同样的IReadOnlyCollection
(或IReadOnlyList
):
[ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
public class Sheep
{
public IReadOnlyCollection<string> Children { get; set; }
public Sheep()
{
Children = new List<string>();
}
}
我得到一个异常:
无法解析为System.Collections.Generic.IReadOnlyCollection`1 [[System.String,mscorlib程序,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089]]
因此,一个合适的添加方法,有没有办法使protobuf网手柄成员IReadOnlyCollection
/IReadOnlyList
?
编辑:我已经开了一个问题,这个功能对项目的资源库:Support IReadOnlyCollection/IReadOnlyList members
您正在使用哪个protobuf库?一个由marc? –
@YuvalItzchakov是的,protobuf网。 Skeet's是\t protobuf-csharp-port。 – i3arnon