HighTechTalks DotNet Forums  

GetMethods function returns Protected even if BindingFlags.Public is given

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss GetMethods function returns Protected even if BindingFlags.Public is given in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Reshma
 
Posts: n/a

Default GetMethods function returns Protected even if BindingFlags.Public is given - 05-12-2004 , 01:51 AM






GetMethods function returns Protected members in the following statemen

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 MyTypeClas

public void MyMethods(

}

public int MyMethods1(

return 3
}

protected String MyMethods2(

return "hello"
}
}

public class TypeMai

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())

}



Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default RE: GetMethods function returns Protected even if BindingFlags.Public is given - 09-03-2004 , 07:44 AM






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());
}
}
}

Quote:


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.