public GetType ( System systemType ) : ICLRType | ||
systemType | System | |
Результат | ICLRType |
// Use this for initialization void Start() { //创建CLRSharp环境 env = new CLRSharp.CLRSharp_Environment(new LSharpLogger()); //加载L#模块 TextAsset dll = Resources.Load("Controller.dll") as TextAsset; TextAsset pdb = Resources.Load("Controller.pdb") as TextAsset; System.IO.MemoryStream msDll = new System.IO.MemoryStream(dll.bytes); System.IO.MemoryStream msPdb = new System.IO.MemoryStream(pdb.bytes); //env.LoadModule (msDll);//如果无符号是pdb的话,第二个参数传null env.LoadModule(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider()); //Pdb //env.LoadModule(msDll, msMdb, new Mono.Cecil.Mdb.MdbReaderProvider());//如果符号是Mdb格式 Debug.Log("LoadModule Controller.dll done."); //step01建立一个线程上下文,用来模拟L#的线程模型,每个线程创建一个即可。 CLRSharp.ThreadContext context = new CLRSharp.ThreadContext(env); Debug.Log("Create ThreadContext for L#."); //step02取得想要调用的L#类型 CLRSharp.ICLRType wantType = env.GetType("Controller.Entry"); //用全名称,包括命名空间 Debug.Log("GetType:" + wantType.Name); //和反射代码中的Type.GetType相对应 //step03 静态调用 //得到类型上的一个函数,第一个参数是函数名字,第二个参数是函数的参数表,这是一个没有参数的函数 CLRSharp.IMethod method01 = wantType.GetMethod("Log", CLRSharp.MethodParamList.constEmpty()); method01.Invoke(context, null, null); //第三个参数是object[] 参数表,这个例子不需要参数 //这是个静态函数调用,对应到代码他就是HotFixCode.TestClass.Test1(); ////step04 成员调用 ////第二个测试程序是一个成员变量,所以先要创建实例 //CLRSharp.IMethod methodctor = wantType.GetMethod(".ctor", CLRSharp.MethodParamList.constEmpty());//取得构造函数 //object typeObj = methodctor.Invoke(context, null, null);//执行构造函数 ////这几行的作用对应到代码就约等于 HotFixCode.TestClass typeObj =new HotFixCode.TestClass(); //CLRSharp.IMethod method02 = wantType.GetMethod("Test2", CLRSharp.MethodParamList.constEmpty()); //method02.Invoke(context, typeObj, null); ////这两行的作用就相当于 typeOBj.Test2(); // //var list = CLRSharp.MethodParamList.Make(env.GetType(typeof(int)), env.GetType(typeof(string))); //CLRSharp.IMethod method03 = wantType.GetMethod("Test2", list); //method03.Invoke(context, typeObj, new object[] { 1234, "abcddd" }); ////这两行的作用就相当于 typeOBj.Test2(1234,"abcddd"); }
// Use this for initialization void Start() { //创建CLRSharp环境 env = new CLRSharp.CLRSharp_Environment(new LSharpLogger()); //加载L#模块 TextAsset dll = Resources.Load("Controller.dll") as TextAsset; TextAsset pdb = Resources.Load("Controller.pdb") as TextAsset; System.IO.MemoryStream msDll = new System.IO.MemoryStream(dll.bytes); System.IO.MemoryStream msPdb = new System.IO.MemoryStream(pdb.bytes); //env.LoadModule (msDll);//如果无符号是pdb的话,第二个参数传null env.LoadModule(msDll, msPdb, new Mono.Cecil.Pdb.PdbReaderProvider());//Pdb //env.LoadModule(msDll, msMdb, new Mono.Cecil.Mdb.MdbReaderProvider());//如果符号是Mdb格式 Debug.Log("LoadModule Controller.dll done."); //step01建立一个线程上下文,用来模拟L#的线程模型,每个线程创建一个即可。 CLRSharp.ThreadContext context = new CLRSharp.ThreadContext(env); Debug.Log("Create ThreadContext for L#."); //step02取得想要调用的L#类型 CLRSharp.ICLRType wantType = env.GetType("Controller.Entry");//用全名称,包括命名空间 Debug.Log("GetType:" + wantType.Name); //和反射代码中的Type.GetType相对应 //step03 静态调用 //得到类型上的一个函数,第一个参数是函数名字,第二个参数是函数的参数表,这是一个没有参数的函数 CLRSharp.IMethod method01 = wantType.GetMethod("Log", CLRSharp.MethodParamList.constEmpty()); method01.Invoke(context, null, null);//第三个参数是object[] 参数表,这个例子不需要参数 //这是个静态函数调用,对应到代码他就是HotFixCode.TestClass.Test1(); ////step04 成员调用 ////第二个测试程序是一个成员变量,所以先要创建实例 //CLRSharp.IMethod methodctor = wantType.GetMethod(".ctor", CLRSharp.MethodParamList.constEmpty());//取得构造函数 //object typeObj = methodctor.Invoke(context, null, null);//执行构造函数 ////这几行的作用对应到代码就约等于 HotFixCode.TestClass typeObj =new HotFixCode.TestClass(); //CLRSharp.IMethod method02 = wantType.GetMethod("Test2", CLRSharp.MethodParamList.constEmpty()); //method02.Invoke(context, typeObj, null); ////这两行的作用就相当于 typeOBj.Test2(); // //var list = CLRSharp.MethodParamList.Make(env.GetType(typeof(int)), env.GetType(typeof(string))); //CLRSharp.IMethod method03 = wantType.GetMethod("Test2", list); //method03.Invoke(context, typeObj, new object[] { 1234, "abcddd" }); ////这两行的作用就相当于 typeOBj.Test2(1234,"abcddd"); }
void InitTest() { var bytes = Resources.Load <TextAsset>("unittestdll.dll").bytes; var bytespdb = Resources.Load <TextAsset>("unittestdll.pdb").bytes; //var bytes = Resources.Load<TextAsset>("unittestdll2.dll").bytes; //var bytesmdb = Resources.Load<TextAsset>("unittestdll2.dll.mdb").bytes;//现在支持mdb了 System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.IO.MemoryStream mspdb = new System.IO.MemoryStream(bytespdb); //System.IO.MemoryStream msmdb = new System.IO.MemoryStream(bytesmdb); //Log(" L# Ver:" + env.version); try { env.LoadModule(ms, mspdb, new Mono.Cecil.Pdb.PdbReaderProvider()); //env.LoadModule(ms, msmdb, new Mono.Cecil.Mdb.MdbReaderProvider()); } catch (Exception err) { Log_Error(err.ToString()); Log_Error("模块未加载完成,请检查错误"); } ResetTest(); Log(" Got Test:" + tests.Count); env.RegType(new TypeForGameObject(env)); //for aot env.GetType(typeof(Dictionary <int, string>)); env.GetType(typeof(Dictionary <int, object>)); env.GetType(typeof(Dictionary <int, CLRSharp.CLRSharp_Instance>)); env.GetType(typeof(Dictionary <int, Action>)); env.GetType(typeof(Dictionary <int, Action <MyClass2> >)); env.GetType(typeof(Dictionary <Int16, Action>)); env.GetType(typeof(LinkedList <int>)); env.GetType(typeof(int[, ])); env.GetType(typeof(List <CLScriptExt.Student>)); env.GetType(typeof(List <Vector3>)); env.GetType(typeof(List <int>[])); env.GetType(typeof(List <List <int> >)); env.GetType(typeof(List <List <List <int> > >)); env.GetType(typeof(Vector3[])); env.GetType(typeof(System.Collections.Generic.IEnumerable <int>)); TestDele.instance.AddDeleT3 <int, string>(null); CLScriptExt.Student s = new CLScriptExt.Student(); s.ToString2 <int>(2);//call once will help. CLScriptExt.P2.TestS2 <int, int>(); //for aot dele CLRSharp.Delegate_Binder.RegBind(typeof(Action <int>), new CLRSharp.Delegate_BindTool <int>()); CLRSharp.Delegate_Binder.RegBind(typeof(Action <MyClass2>), new CLRSharp.Delegate_BindTool <MyClass2>()); CLRSharp.Delegate_Binder.RegBind(typeof(Action <int, int>), new CLRSharp.Delegate_BindTool <int, int>()); CLRSharp.Delegate_Binder.RegBind(typeof(Action <int, int, int>), new CLRSharp.Delegate_BindTool <int, int, int>()); CLRSharp.Delegate_Binder.RegBind(typeof(Func <int, int, int>), new CLRSharp.Delegate_BindTool_Ret <int, int, int>()); CLRSharp.Delegate_Binder.RegBind(typeof(Action <int, string>), new CLRSharp.Delegate_BindTool <int, string>()); CLRSharp.Delegate_Binder.RegBind(typeof(Action <string>), new CLRSharp.Delegate_BindTool <string>()); CLRSharp.Delegate_Binder.RegBind(typeof(Action <bool>), new CLRSharp.Delegate_BindTool <bool>()); }