开发者

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

开发者 https://www.devze.com 2023-01-04 04:47 出处:网络
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

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

精彩评论

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