ILRuntime注意事项
1. Const在IL反射读取失败
Public static class DynamicSystemEnum
{
public const string LBS_Scene = "Scene";
}
解决方案:在IL中如果使用反射读取时,不能使用Const。必须改成Static。
2. 在IL中使用Activator.CreateInstance实例化时,当构造函数有参数时不执行
解决方案:Activator.CreateInstance的参数类型必须与构造函数参数的类型一致。参数的类型不可以使用基类。
3. 在IL中获取Attribute特性时,直接使用System.Reflection空间命名下面的扩展函数,返回值为null
解决方案:只使用Type.GetCustomAttributes(Type attributeType,false)来获取。
4. 在IL中使用as做类型转换时,返回值为null
解决方案:尽量使用强制转换
4. 在IL中获取热更代码中的Assembly的所有Types。
解决方案:使用IL的AppDomain.LoadedTypes获取。