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

Non-public types #226

Open asdfgasdfsafgsdfa opened 7 years ago

asdfgasdfsafgsdfa commented 7 years ago

Is there any reason why only public types can be serialized? The library should not decide what is allowed to be serialized and what not. Why create an artificial limitation like that?

If there any way to turn this off?

I want to use msgpack to save private datatypes in my application. And I also don't want to have my network messages public for everyone to see. It would be bad design to make those types public.

yfakariya commented 7 years ago

This is technical limitation in old days.

MsgPack for CLI internally uses IL generation (via System.Reflection.Emit) and/or source code generation (via code DOM) to generate serializer code. Both of them require the target type is public. Currently, it is possible when we use:

  1. Via reflection.
  2. Via DynamicMethod. As far as I know, msgpack for C# internally uses this technique, but this will take long time to implement.
itaign commented 7 years ago

You can also use MessagePackMember attribute