开发者

Silverlight reflection

With ASP.NET, for instance, we could reflect on the assem开发者_如何学Goblies 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?


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜