银光反射
例如,使用 ASP.NET,我们可以反映 AppDomain 中的程序集,或者使用类型获取有关类的元数据(属性、方法等)。在 Silverlight 中用于提取类元数据、提取依赖属性等的技术是什么?
With ASP.NET, for instance, we could reflect on the assemblies in an AppDomain, or using the type we could get the metadata about the class (props, methods, etc.). What is the technique used to extract metadata on a class, extract dependency properties, etc., in Silverlight?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Silverlight 中存在反射,完整的 .NET Framework 中提供了 API 的子集。
一个显着的区别是您无法反映 Silverlight 中的私有成员(或者也许您可以在您自己的程序集中反映,但边界应该很快就会变得明显)。这是一项安全功能,可确保您不会弄乱框架本身的内部结构。
除了这个(诚然,相当大的)限制之外,反射应该基本相同。
Reflection exists in Silverlight, with a subset of the APIs provided in the full .NET Framework.
One notable difference is that you can't reflect onto private members in Silverlight (or maybe you can inside your own assembly, but the boundaries should become apparent pretty quickly). This is a security feature to ensure you don't go messing with the internals of the framework itself.
Other than that (admittedly, rather large) limitation, Reflection should be basically the same.
除了 Austin 所说的之外,Silverlight 中反射的规则是您只能通过反射访问您可以通过普通代码访问的任何内容。所以这不仅仅是私人成员的问题。您只能在类本身或继承它的任何类中反映受保护的成员。
API 有许多缺失的部分,但总的来说,大多数事情都应该是可能的,即使它们比完整的 .NET 需要更多的工作
In addition to what Austin said, the rule with Reflection in Silverlight is that you can only access via reflection whatever you could access via normal code. So it's not just about private members. You can reflect over protected members only in the class itself or in any class inheriting it.
There are numerous missing pieces of the API but in general most things should be possible, even if they require a bit more work than in full .NET
反思的安全考虑
反射提供了获取有关类型和成员的信息以及访问成员的能力。在 Silverlight 中,您可以使用反射来执行以下任务:
枚举类型和成员,并检查它们的元数据。
枚举并检查程序集和模块。
访问公共成员。
访问调用代码的程序集中的内部成员(在 Visual Basic 中为友元成员)。 (在反射中,这称为程序集级访问。)
在 Silverlight 中,不能使用反射来访问私有类型和成员。如果类型或成员的访问级别会阻止您在静态编译的代码中访问它,则您无法使用反射动态访问它。
Security Considerations for Reflection
Reflection provides the ability to obtain information about types and members, and to access members. In Silverlight, you can use reflection to perform the following tasks:
Enumerate types and members, and examine their metadata.
Enumerate and examine assemblies and modules.
Access public members.
Access internal members (Friend members in Visual Basic) in the calling code's assembly. (In reflection, this is referred to as assembly-level access.)
In Silverlight, you cannot use reflection to access private types and members. If the access level of a type or member would prevent you from accessing it in statically compiled code, you cannot access it dynamically by using reflection.