2020年4月

Debug.Log("GetTypes().Length: " + Assembly.GetExecutingAssembly().GetTypes().Length);
Debug.Log("CodeBase: " + Assembly.GetExecutingAssembly().CodeBase);
Debug.Log("FullName: " + Assembly.GetExecutingAssembly().FullName);
Debug.Log("GlobalAssemblyCache: " + Assembly.GetExecutingAssembly().GlobalAssemblyCache);
Debug.Log("Location: " + Assembly.GetExecutingAssembly().Location);


Windows-Andorid,ios
GetTypes().Length: 5383
CodeBase: file:///D:/xx/Library/ScriptAssemblies/Assembly-CSharp.dll
FullName: Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
GlobalAssemblyCache: False
Location: D:\xx\Library\ScriptAssemblies\Assembly-CSharp.dll

Mac
GetTypes().Length: 5383
CodeBase: file:///Users/xx/Library/ScriptAssemblies/Assembly-CSharp.dll
FullName: Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
GlobalAssemblyCache: False
Location: Users/xx/Library/ScriptAssemblies/Assembly-CSharp.dll

Android
GetTypes().Length: 5368
CodeBase: file:///data/app/xx/base.apk/assets/bin/Data/Managed/Assembly-CSharp.dll
FullName: Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
GlobalAssemblyCache: False
Location: data/app/xx/base.apk/assets/bin/Data/Managed/Assembly-CSharp.dll

Ios
GetTypes().Length: 5368
CodeBase: file:///private/var/containers/Application/xx/test1.app/Assembly-CSharp.dll
FullName: Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
GlobalAssemblyCache: False
Location: 
Assembly.GetExecutingAssembly()

IOS上的反射是部分支持,支持使用反射读取源代码,但不支持使用反射动态生成可执行代码, 不支持以动态方式创建新的方法和类型

// android, ios 通过
var instance1 = System.Activator.CreateInstance<TestInstance>();
var instance2 = System.Activator.CreateInstance(typeof(TestInstance)) as TestInstance;
Debug.Log(instance1.i);
Debug.Log(instance2.i);
System.Reflection.ConstructorInfo ci = typeof(TestInstance).GetConstructors()[0];
var instance3 = ci.Invoke(null) as TestInstance;
Debug.Log(instance3.i);


AssemblyName an = new AssemblyName("TestAssemblyName");
// ios平台下没有 AssemblyBuilder, android有
System.Reflection.Emit.AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.Run);
View Code

猜你喜欢

转载自www.cnblogs.com/revoid/p/12606139.html