protobuf-net v2 and Monotouch : How does it mix?

后端 未结 2 1996
长发绾君心
长发绾君心 2021-02-04 17:32

I have been trying to use protobuf-net with MonoTouch but I have no idea how, and despite having heard that it is possible, I haven\'t been able to find any tutorial or any exam

2条回答
  •  粉色の甜心
    2021-02-04 18:08

    It is actually pretty much the same as described in this blog entry by Friction Point Studios. Since meta-programming on the device is not really an option, the trick is to pre-generate a serialization dll. This can be done by creating a small console exe (this is just a tool - it isn't designed to be pretty) that configures a RuntimeTypeModel (by adding the types you are interested in), and then call .Compile(...):

    var model = TypeModel.Create();
    model.Add(typeof (ProtoObject), true);
    model.Compile("MySerializer", "MySerializer.dll");
    

    This generates a serializer dll; simply reference this dll (along with the iOS version protobuf-net), and use the serializer type in the dll to interact with your model:

    var ser = new MySerializer();
    ser.Serialize(dest, obj); // etc
    

提交回复
热议问题