If you use Java reflection you should get the proper results.
In the present case where you have used .Net Reflection, you need to
compile your code using the '/ss' option of the J# compiler to get the
results that you expect.
For details, please visit the link
http://msdn.microsoft.com/library/de...us/dv_vjsample
/html/vjsamscopingsampleusingsecurescoping.asp
Thank you,
Diganta Roy
Microsoft Visual J# .NET Product Team
--------------------
Quote:
Thread-Topic: GetMethods function returns Protected even if
BindingFlags.Public is given
thread-index: AcQ35RyRgVR2bjN6SE2UeU7VjQLScA==
X-WN-Post: microsoft.public.dotnet.vjsharp
From: =?Utf-8?B?UmVzaG1h?= <anonymous (AT) discussions (DOT) microsoft.com
Subject: GetMethods function returns Protected even if BindingFlags.Public
is given
Date: Tue, 11 May 2004 22:51:03 -0700
Lines: 55
Message-ID: <72A9FA16-8D04-43FE-86DA-0F9CC5267859 (AT) microsoft (DOT) com
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.vjsharp
Path: cpmsftngxa10.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:6022
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.vjsharp
GetMethods function returns Protected members in the following statement |
MethodInfo myArrayMethodInfo[] = myType.GetMethods(BindingFlags.Public |
BindingFlags.Instance | BindingFlags.DeclaredOnly);
The whole code is
import System .* ;
import System.Reflection .* ;
import System.Reflection.Emit .* ;
// Create a class having two public methods and one protected method.
public class MyTypeClass
{
public void MyMethods()
{
}
public int MyMethods1()
{
return 3;
}
protected String MyMethods2()
{
return "hello";
}
}
public class TypeMain
{
public static void main(String[] args)
{
Type myType = MyTypeClass.class.ToType();
// Get the public methods.
MethodInfo myArrayMethodInfo[] = myType.GetMethods(BindingFlags.Public |
BindingFlags.Instance | BindingFlags.DeclaredOnly);
Console.WriteLine("\nThe number of public methods is {0}.",
(Int32)(myArrayMethodInfo.length));
// Display all the methods.
DisplayMethodInfo(myArrayMethodInfo);
// Get the nonpublic methods.
MethodInfo myArrayMethodInfo1[] =
myType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.DeclaredOnly);
Console.WriteLine("\nThe number of protected methods is {0}.",
(Int32)(myArrayMethodInfo1.length));
// Display information for all methods.
DisplayMethodInfo(myArrayMethodInfo1);
}
public static void DisplayMethodInfo(MethodInfo myArrayMethodInfo[])
{
// Display information for all methods.
for (int i = 0; i < myArrayMethodInfo.length; i++) {
MethodInfo myMethodInfo = ( MethodInfo)myArrayMethodInfo.get_Item(i);
Console.WriteLine("\nThe name of the method is {0}.",
myMethodInfo.get_Name());
}
}
}