Estamos desarrollando un juego en línea multiplataforma usando el motor unity3d(monotouch) (C#), y usamos protobuf-net (gracias a Marc Gravell) como protocolo. Como sabemos, la reflexión no funciona en iOS. Apple no permite que el código se genere dinámicamente. Revisamos el blog de Marc (http://marcgravell.blogspot.com/), y encontramos que la protobuf-net v2 anterior (aunque aún no está completa) puede evitar el problema de reflexión.
hicimos algunas pruebas e intentamos compilar previamente el código de serialización en un archivo dll, sin embargo, cuando lo ejecutamos en ios, recibimos el siguiente mensaje.
>
System.IO.FileNotFoundException has been thrown > “Could not load file or assembly “DataBuilder , Version=0.0.0.0 , > Culture = neutrual , PublicKeyToken = > null ”” or one of its dependencies.”aquí está nuestro código dll de compilación
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ProtoBuf; using ProtoBuf.Meta; using Data; using System.Reflection; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var bb = TypeModel.Create(); bb.Add(typeof(Customer), true); bb.Compile("DataBuilder", "databuilder.dll"); } } }aquí está nuestro código de prueba
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Data; using System.IO; using ProtoBuf; using ProtoBuf.Meta; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var creater = new DataBuilder(); // that's it var dd = new Data.Customer(); dd.Name = "Hellow World"; dd.CustomerId = "1232"; MemoryStream mm = new MemoryStream(); creater.Serialize(mm, dd); mm.Seek(0, SeekOrigin.Begin); Data.Customer c = (Data.Customer)creater.Deserialize(mm, null, typeof(Data.Customer)); Console.WriteLine(c.Name); } } }Compilamos dll en el entorno de Windows (compact framework .net 3.5), tal vez no funcionó en monotouch.