leejw51 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

Support for serialization of ReadOnlyCollection. #254

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Would be nice to be able to serialize and deserialize immutable objects that 
contain ReadOnlyCollection and possibly the new ReadOnlyDictionary.

---------------------------------------------------------------------

Suggested hack/fix would be to use reflections to call the 
ReadOnlyCollection/ReadOnlyDictionary constructor (with List/Dictionary as a 
parameter) after the List/Dictionary are created but before the cast back to 
the original type.  Probably a decent spot to do this is in TypeModel.cs 
TryDeserializeList() after the while loop that creates List (line 723 @r470). 
Something along the lines of (but very likely not correct):

if (list != null && listType.FullName.Contains("ReadOnly"))
{
    // Call reflection constructor
    value = Activator.CreateInstance(listType, new object[]{ value });
}

Mark
mark.butowski@gmail.com

Original issue reported on code.google.com by mark.but...@gmail.com on 24 Nov 2011 at 6:41

GoogleCodeExporter commented 9 years ago
Hi Marc,

Any thoughts on when this might be possible?  What do you think of the proposed 
solution?

Mark

Original comment by mark.but...@gmail.com on 21 Jan 2012 at 12:21

GoogleCodeExporter commented 9 years ago
think the proposed solution is a bit brittle as a name-based thing... But 
simply haven't had chance to take a detailed look yt

Original comment by marc.gravell on 21 Jan 2012 at 10:51