-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Sitaraman
Message 1 in Discussion

Hi All   Problem :   You can pass a MethodBase object to the 
Microsoft.VisualBasic.CompilerServices.Utils.MethodToString() method and get the 
coplete signature of the method.Right!!!. Now when u pass a Public or private function 
it gives the correct modifier.  However, when you pass a friend function's methodinfo 
to this function it does not give the correct modifier.  For example if i have three 
functions in a class "Class2" and i reflect thru it using a Module as follows     How 
to test this behaviour :       The Code Class c2
    Public Sub x()     End Sub
    Private Sub y()     End Sub
    Friend Sub z()     End Sub End Class   Module Module1     Sub main()
        Dim l_objMethodInfo As MemberInfo
        Dim l_objMethodsInfo() As MemberInfo
        Dim xx As New Class2()
        l_objMethodsInfo = xx.GetType.GetMethods(BindingFlags.Instance Or 
BindingFlags.Static Or _
                    BindingFlags.Public Or BindingFlags.NonPublic)
        For Each l_objMethodInfo In l_objMethodsInfo
            
Console.WriteLine(Microsoft.VisualBasic.CompilerServices.Utils.MethodToString(l_objMethodInfo))
        Next
        Console.ReadLine()
    End Sub
End Module          The Output   Overrides Sub Finalize ( )
Overrides Public Function GetHashCode ( ) As Integer
Overrides Public Function Equals ( ByVal obj As Object ) As Boolean
Overrides Public Function ToString ( ) As String
Public Sub x ( ) ' SR : This is OK
Private Sub y ( ) 'SR :  This is also OK
Sub z ( ) ' SR : No Modifier!!!!!!!!!!!!!!
Public Function GetType ( ) As System.Type
Function MemberwiseClone ( ) As Object
      Here note that for the friend function "Sub z ( )",  the access modifier 
"Friend" is not returned by the 
Microsoft.VisualBasic.CompilerServices.Utils.MethodToString(l_objMethodInfo)) method   
  Analysis :   Went ahead with the disassembly of the 
Microsoft.VisualBasic.CompilerServices.Utils.MethodToString()  function and my 
observation is as follows      The DisAssembly   L_004b: callvirt 
MethodBase.get_IsPrivate
L_0050: brfalse.s L_0060
L_0052: ldloc.2 
L_0053: ldstr "Private "
L_0058: call String.Concat
L_005d: stloc.2 
L_005e: br.s L_0074
L_0060: ldloc.3 
L_0061: callvirt MethodBase.get_IsPrivate 'SR : ?????????????????????????????????????
L_0066: brfalse.s L_0074
L_0068: ldloc.2 
L_0069: ldstr "Friend "
L_006e: call String.Concat
L_0073: stloc.2 
L_0074: ldloc.s V_5
L_0076: brfalse.s L_0081
L_0078: ldloc.s V_5        This is like writing    if l_objMethodInfo.IsPrivate() then 
     l_str1=String.concat(l_str1,"Private ") endif   if l_objMethodInfo.IsPrivate() 
then       l_str1=String.concat(l_str1,"Friend ") endif   
???????????????????????????????????????????????????????????????????????      whereas 
the code should have been like       if l_objMethodInfo.IsPrivate() then      
l_str1=String.concat(l_str1,"Private ") endif   if l_objMethodInfo.IsAssembly() then   
    l_str1=String.concat(l_str1,"Friend ") endif      This is the reason why this 
function does not give the modifier properly when u pass a Friend function's 
MethodInfo as parameter.    Would appreciate comments from the group on the same...   
Also hope MS corrects this in the next version!!!    regards,   sr   p.s. Two 
questions:    1. wrt a post on this site a few days 
ago("http://groups.msn.com/BDotNet/general.msnw?action=get_message&mview=0&ID_Message=4281&all_topics=0";),
  When u try to create an instance of a class whose constructor is a "Friend", VS.Net 
gives a wronf error message in the tooltip "BasicImplementation.BasicClass.Private 
overloads Sub New ()' is not accessible in this context because it is Private"  
instead of  "BasicImplementation.BasicClass.Friend overloads Sub New ()' is not 
accessible in this context because it is Friend"   Is the bug mentioned above the 
reason for the wrong error message of VS.Net? Does VS.Net call this function and 
therefore does not get the correct modifier???   2. When i type 
Microsoft.VisualBasic.CompilerServices. it does not show the types in that namespace 
in VS.Net.  How do u block the types of ur assembly from being displayed thru VS.Net 
intellisense?  

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/BDotNet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to