分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

IlRuntime + protobuf-net

发布时间:2023-09-06 02:14责任编辑:林大明关键词:暂无标签

环境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生成文件里

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

 

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

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

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

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

IlRuntime + protobuf-net

原文地址:https://www.cnblogs.com/marcher/p/9650429.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved