You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
below sample code fails since deserializer does not restore the collection items, even if collections are initialized.
Making the "Collection" property writable { get; set; } would solve that, but raises CA2227 warnings.
When restoring/deserializing collection properties, code could check if collections are alreay initialized, and add the restore items to the existing collection, instead of trying to set the collection property itself value.Collection = __Collection;
If it's not intended to handle readonly collection properties, code analysis warning or runtime error should be raised, and also the properties should be exempted from serizalization.
[MemoryPackable]
public partial class CollectionTest
{
public Collection<string> Collection { get; } = new Collection<string>();
}
internal class Program
{
static async Task Main(string[] args)
{
CollectionTest sourceCollection = new CollectionTest();
sourceCollection.Collection.Add("1234");
sourceCollection.Collection.Add("5678");
Pipe bufferPipe = new Pipe();
MemoryPackSerializer.Serialize(bufferPipe.Writer, sourceCollection);
_ = await bufferPipe.Writer.FlushAsync().ConfigureAwait(false);
ReadResult resultBuffer = await bufferPipe.Reader.ReadAsync().ConfigureAwait(false);
CollectionTest resultCollection = MemoryPackSerializer.Deserialize<CollectionTest>(resultBuffer.Buffer);
Debug.Assert(resultCollection.Collection.Count == 2);
}
}
The text was updated successfully, but these errors were encountered:
below sample code fails since deserializer does not restore the collection items, even if collections are initialized.
Making the "Collection" property writable { get; set; } would solve that, but raises CA2227 warnings.
When restoring/deserializing collection properties, code could check if collections are alreay initialized, and add the restore items to the existing collection, instead of trying to set the collection property itself
value.Collection = __Collection;
If it's not intended to handle readonly collection properties, code analysis warning or runtime error should be raised, and also the properties should be exempted from serizalization.
The text was updated successfully, but these errors were encountered: