Bru*_*ill 6 c# iphone xamarin.ios
我遇到了一个问题,即反射方法GetMethod没有为类返回静态方法.这只是在实际的iPhone上出错了; 在模拟器上它正常工作.我尝试过以下方法:
MethodInfo methInfo = _type.GetMethod (methodName);
Run Code Online (Sandbox Code Playgroud)
和
MethodInfo methInfo = _type.GetMethod (methodName, System.Reflection.BindingFlags.Static);
Run Code Online (Sandbox Code Playgroud)
但这些都不返回methodName中指定的方法.指定的方法确实存在,因为它在模拟器上工作.我已经使用调试器确认我的成员变量_type确实包含正确的类类型引用.我尝试检索的方法在类中声明为public.
有没有人之前遇到过这个或者知道为什么这会在模拟器上运行而不是在实际的iphone上运行?
反思虽然在iOS上无法完全运行,但仍有效.问题是链接器在设备配置上被激活,并且因为没有使用它而切断了该方法.链接器无法"看到"反射调用.
如果它是自定义对象,请使用PreserveAttribute进行装饰:
[Preserve(AllMembers=true)]
public class MyClass
{}
Run Code Online (Sandbox Code Playgroud)
如果它是SDK中的对象,您有两个选择:
| 归档时间: |
|
| 查看次数: |
1188 次 |
| 最近记录: |