Sunday, May 22, 2016

serialization layer

[1hr] Wrote up engineering design goals for MOSS, as well as user experience goals for a hypothetical game that might sit on top of MOSS.

[3hrs] Got container serialization working for Lists. All other Collections should follow trivially. I think a new method-pair will be necessary for conventional C# arrays. Then associative containers, and I'll be done with this part. The hard bit was of course coercing the C# type system to not complain about all the vague things I was doing. For instance, I had:

object entry = Serializers.deserializeInternal( i_reader ); // i_reader is a BinaryReader
container.Add( entry); // container is a dynamic created via reflection.

This doesn't fly. The runtime can figure out that the List indeed has an Add method, but it's detecting as Add<int>, and you can't pass an Object to Add<int>, even if the Object happens to be an int. I don't think there's any general way to do a cast like:

Type someType = object.GetType();
(someType)object;

Solution? Make entry also be dynamic. Duh. Just keep making things dynamic until it works. Should have thought of that immediately.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.