/// <summary> /// 启动热更实例,包括跨域函数注册、跨域类装配器注册、重定向方法注册 /// </summary> public void Start() { if (IsStart) { return; } else { } IsStart = true; IHotFixConfig config = this.GetAppILRuntime().GetHotFixConfig(); config.RegisterMethods?.Invoke(ILAppDomain);//注册函数适配器 CrossBindingAdaptor[] list = config.Adapters; int max = list == default ? 0 : list.Length; for (int i = 0; i < max; i++) { ILAppDomain.RegisterCrossBindingAdaptor(list[i]);//注册跨域类适配器 } #if ILRUNTIME LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(ILAppDomain); //注册热更端JSON解析器 #endif ILRuntime.Runtime.Generated.CLRBindings.Initialize(ILAppDomain); //注册重定向的方法 }
//创建实例对象 public object CreateInstance(string typeFullName, params object[] args) { object instance; #if ILRuntime instance = ILAppDomain.Instantiate(typeFullName, args); #else Type type = ReflectAssembly.GetType(typeFullName); instance = Activator.CreateInstance(type, args); #endif return(instance); }
//调用一次的方法 public object InvokeOne(string typeFullName, string methodName, object instance, params object[] args) { if (instance != null) { #if ILRuntime if (ILAppDomain != null) { return(ILAppDomain.Invoke(typeFullName, methodName, instance, args)); } #else if (ReflectAssembly != null) { Type type = ReflectAssembly.GetType(typeFullName); return(type.GetMethod(methodName).Invoke(instance, args)); } #endif } return(null); }