msgpack / msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
http://msgpack.org
Apache License 2.0
834 stars 175 forks source link

Allow the serialization of non-collection types implementing IEnumerable #173

Closed samcragg closed 8 years ago

samcragg commented 8 years ago

This is designed to fix issue #169

I've added a compatibility option to disable the new behaviour (AlwaysAssumeCollections) and all the unit tests to pass with the refactored code, plus there's an additional one showing the desired behaviour.

Since this is my first pull request let me know if there's anything you need me to do

samcragg commented 8 years ago

I've just moved the test to AutoMessagePackSerializerTest.ttinclude (and removed the [Serializable] as requested) and it looks like some of the new generated tests fail (I think I've focused on one area that was causing me pain but the unit tests cover far more edge cases that need fixing first).

Let me investigate and I'll add a new commit with the changes before anything gets merged

yfakariya commented 8 years ago

I'm trying to add tests for error cases, so I found some extra issues on your PR. Sorry for taking back what I said, please check my comments. In addition, I will fix and push some bugs they prevent your fix working correctly in an hour.

Here are the instructions and requests to testing:

  1. Please add test following cases:
    • Non-generic version of NonCollectionType
    • If AlwaysAssumeCollections is not set to default, SerializationException is thrown. This case should also be added for non generic variant.
  2. Put the NonCollectionType and non generic counter parts to AutoMessagePackSerializerTest.Types.tt.
  3. Go to PreGeneratedSerializerActivator.Types.tt, put result.Add( typeof( ... ) ); in the end of the method (after #endif) for both of generic one and non generic one.
  4. Go to PreGenerateSerializerGenerator.cs, remove comment out of the [Test]. And execute the GenerateFiles method, then MessagePack_Serialization_xxx.cs (xxx is type name of generic one and non generic one) will be generated in %SystemDrive%\temp-gen. Move the files to MsgPack.UnitTest\gen folder.
  5. Open MsgPack.compat.sln and go to MsgPack.UnitTest.Net35 project.
  6. Run PreGenerateSerializerGenerator.GenerateFiles() test. New files will be generated in %SystemDrive%\temp-gen35. Move the files to MsgPackUnitTest.Net35\gen folder.
yfakariya commented 8 years ago

Thank you for great work! I merged with a few tweaking.