Knowing Accessibility of Methods Using Reflection

Knowing Accessibility of Methods Using Reflection

While programming, one inquiry would be to know the if the methods from the given class could be accessible or not from any object, from derived class, from assembly or from derived & assembly…
Knowing ahead for time these factors would reduce the error theater from running.
Say a class with the following definition is given:

class Person{
     private void privateMethod(){}
     public void publicMethod(){}
     protected void protectedMethod(){}
     internal void internalMehtod(){}
     public static void staticMethod(){}
     public virtual void virtualMethod(){}
     protected internal void internalProtectedMethod(){}
}

So, while trying to access the methods of the Person class and wanted to know accessibility – no problem..
Dot Net has provided the following methods for this specific usage under the implementation of reflection

.Name - tells the name of the method
.IsPublic - checks if the method in the class is public or not (public)
.IsStatic - checks if the method is static (static)
.IsVirtual - checks if the method is virtual (virtual)
.IsAssembly - answers if it can be accessed from assembly (internal)
.IsFamily - answers if it can be accessed from derived class (protected)
.IsFamilyOrAssembly - from derived or assebmbly (protected internal)
.IsFamilyAndAssembly - from derived and assembly 

Look @
http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.isfamily.aspx For example and application

Using Facebook API to post articles from PHP

Check if Function Exists in Javascript

AbstractSureFireMojo Class Missing Maven Surefire

Redirect to home page on 404 – htaccess

Spring Data error: getOutputStream() has already been called for this response

Post to Facebook From app – Using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*