开发者

How to tell whether a class/method is accessible using reflection?

I use a Dynamic Assembly to create derived classes at run time. How can I tell, using reflection, whether the base class and individual methods in the base c开发者_运维问答lass can be used/called from within the derived class in the dynamic assembly?


There are a number of properties on the MethodInfo and Type objects that you can use to query visibility.

For example, for a type you can check IsPublic, IsPrivate, IsNotPublic, IsNested, IsNestedFamOrAssembly, and a whole lot more.

For a method (the MethodInfo object), you've got a similar set: IsPublic,IsPrivate, IsFamilyOrAssembly, etc.

So combine this with information like the Assembly property on a type (so you can tell if Type1 and Type2 are both in the same assembly) and you should be able to get all of the information you need.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜