Silverlight 中的反射限制 [英] Reflection restrictions in Silverlight
问题描述
哪里描述了 Silverlight 类型的众所周知的反射限制?
Where described well-known reflection restrictions for Silverlight types?
例如:如果我尝试使用 PropertyInfo.SetValue
方法设置受保护或私有属性值,我会收到异常 MethodAccessException
.
For example: if I try to set protected or private property value with PropertyInfo.SetValue
method I get an exception MethodAccessException
.
为什么会有这些限制?
推荐答案
出于安全目的,Silverlight 中的反射仅限于编译时可用的内容.大多数情况下,这意味着您只能访问公共成员.
For security purposes, reflection in Silverlight is limited to what is available at compile time. Mostly this means you can only access public members.
以下是 MS 对此的说明:http://msdn.microsoft.com/en-us/library/stfy7tfc(VS.95).aspx
Here's what MS says about it: http://msdn.microsoft.com/en-us/library/stfy7tfc(VS.95).aspx
这样做的原因是 Silverlight 内部结构大多是私有的或主要 Silverlight 程序集内部的.如果我可以在不检查任何参数的情况下调用这些私有函数,我也许可以编写一个 Silverlight 应用程序来读取您的私有文件或类似的东西.
The reason for this is that the Silverlight internals are mostly private or internal to the main Silverlight assembly. If I could call those private functions without any parameter checking, I might be able to write a Silverlight app that reads your private files or something like that.
这篇关于Silverlight 中的反射限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!