环境unity566,.net2.0

下载protobuf-net

https://github.com/mgravell/protobuf-net/tree/r668

因为这个vs2015就可以打开,主干需要2017

下载ILRuntime

https://github.com/Ourpalm/ILRuntime

参照

https://github.com/Ourpalm/ILRuntimeU3D/

搭建1个hotfix工程,1个unity工程,完整工程如下

https://github.com/yingsz/ILRuntime-protobuf-net

遇到的几个问题

1对于hotfix工程里,继承外部类或接口,需要编写adaptor,并注册,网上有教程

2对于hotfix工程不可以既继承外部类,同时又实现外部接口。ProtoMemberAttribute既继承了Attribute,又实现了ICompare.

这个时候需要在外部实现1个类,继承Attribute。并实现接口ICompare,比如叫CompareAttribute,然后ProtoMemberAttribute继续CompareAttribute

但是我简单粗暴的把ICompare删了

3ILRuntime里抛nullreferenceexception,这个是因为protobuf生成文件里

  1. global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
  2. { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }

 

获取方法名字是“global::ProtoBuf.IExtensible.GetExtensionObject”,而ILRuntime里用名字找方法是用的是

  1. if (m == null && method.DeclearingType.IsInterface)
  2. {
  3. m = GetMethod(string.Format("{0}.{1}", method.DeclearingType.FullName, method.Name), method.Parameters, genericArguments, method.ReturnType, true);

名字是“ProtoBuf.IExtensible.GetExtensionObject”,所以会找不到方法,所以需要改成

  1. var m = GetMethod(method.Name, method.Parameters, genericArguments, method.ReturnType, true);
  2. if (m == null && method.DeclearingType.IsInterface)
  3. {
  4. m = GetMethod(string.Format("{0}.{1}", method.DeclearingType.FullName, method.Name), method.Parameters, genericArguments, method.ReturnType, true);
  5. if(m == null)
  6. m = GetMethod(string.Format("global::{0}.{1}", method.DeclearingType.FullName, method.Name), method.Parameters, genericArguments, method.ReturnType, true);
  7. }

IlRuntime + protobuf-net的更多相关文章

  1. python通过protobuf实现rpc

    由于项目组现在用的rpc是基于google protobuf rpc协议实现的,所以花了点时间了解下protobuf rpc.rpc对于做分布式系统的人来说肯定不陌生,对于rpc不了解的童鞋可以自行g ...

  2. Protobuf使用规范分享

    一.Protobuf 的优点 Protobuf 有如 XML,不过它更小.更快.也更简单.它以高效的二进制方式存储,比 XML 小 3 到 10 倍,快 20 到 100 倍.你可以定义自己的数据结构 ...

  3. java netty socket库和自定义C#socket库利用protobuf进行通信完整实例

    之前的文章讲述了socket通信的一些基本知识,已经本人自定义的C#版本的socket.和java netty 库的二次封装,但是没有真正的发表测试用例. 本文只是为了讲解利用protobuf 进行C ...

  4. 在Wcf中应用ProtoBuf替代默认的序列化器

    Google的ProtoBuf序列化器性能的牛逼已经有目共睹了,可以把它应用到Socket通讯,队列,Wcf中,身为dotnet程序员一边期待着不久后Grpc对dotnet core的支持更期待着Wc ...

  5. protobuf的编译安装

    github地址:https://github.com/google/protobuf支持多种语言,有多个语言的版本,本文采用的是在centos7下编译源码进行安装. github上有详细的安装说明: ...

  6. 编译protobuf的jar文件

    1.准备工作 需要到github上下载相应的文件,地址https://github.com/google/protobuf/releases protobuf有很多不同语言的版本,因为我们需要的是ja ...

  7. protobuf学习(2)-相关学习资料

    protobuf官方git地址 protobuf官方英文文档   (你懂的需要FQ) protobuf中文翻译文档 protobuf概述          (官方翻译 推荐阅读) protobuf入门 ...

  8. google protobuf安装与使用

    google protobuf是一个灵活的.高效的用于序列化数据的协议.相比较XML和JSON格式,protobuf更小.更快.更便捷.google protobuf是跨语言的,并且自带了一个编译器( ...

  9. c# (ENUM)枚举组合类型的谷歌序列化Protobuf

    c# (ENUM)枚举组合类型的谷歌序列化Protobuf,必须在序列化/反序列化时加上下面: RuntimeTypeModel.Default[typeof(Alarm)].EnumPassthru ...

随机推荐

  1. CSS之Position全面认识

    CSS的很多其他属性大多容易理解,比如字体,文本,背景等.有些CSS书籍也会对这些简单的属性进行大张旗鼓的介绍,而偏偏忽略了对一些难缠的属 性讲解,有避重就轻的嫌疑.CSS中主要难以理解的属性包括盒型 ...

  2. NodeJS在CentOs7下安装

    node下载地址:https://nodejs.org/en/download/ 1.安装gcc $ yum install gcc-c++ 2.解压最新版本 $ mkdir /usr/local/n ...

  3. datagridview 日期列排序

    1.datagridview 日期列排序 private void Form1_Load(object sender, EventArgs e) { //方法1 dataGridView1.Colum ...

  4. Atitit  文件上传  架构设计 实现机制 解决方案  实践java php c#.net js javascript  c++ python

    Atitit  文件上传  架构设计 实现机制 解决方案  实践java php c#.net js javascript  c++ python 1. 上传的几点要求2 1.1. 本地预览2 1.2 ...

  5. Java获取网卡的mac地址

    为了项目的安全,有时候需要得到电脑的唯一码,比如:网卡的mac地址.和大家分享一下,下面是项目中用到的工具类: import java.io.BufferedReader;import java.io ...

  6. python C example:encode mp3 code

    #include <stdio.h> #include <stdlib.h> #include <lame.h> #define INBUFSIZE 4096 #d ...

  7. java中的static方法和实例方法区别

    1.static方法是大家共享的资源,放在内存堆中,比如村里的河水,每个人都可以取,而且不管你创建多少个实例,该方法在内存中只有一个,节省内存空间, 而且访问速度也是比较快的. 2.实例方法就不同,它 ...

  8. iOS开发--用户点击频繁,多个异步网络请求取消问题?

    一.业务环境描述 当一个view同时添加两个tableView为subView的时候,两个tableView分别为mainTable和subTable. 当用户点击mainTable上的某一条数据时, ...

  9. Java并发编程(八)不变性

    提到不变性我首先想到的就是String这个类了. 之前学习了很多原子性以及可见性的问题:失效数据,丢失更新操作或者某个对象的状态不一致,都与多线程试图访问同一个可变的相关. 如果对象的状态不会发生改变 ...

  10. 设计模式中类的关系之依赖关系(Dependence)

    依赖关系是一种使用关系,特定事物的改变有可能会影响到使用该事物的其他事物,在需要表示一个事物使用另一个事物时使用依赖关系.可以简单的理解,就是一个类A使用到了另一个类B,而这种使用关系是具有偶然性的. ...