Results 1 to 3 of 3

Thread: I think I found a bug

  1. #1

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    I think I found a bug

    I think there is some trouble in Reflection land. Can someone else test this and see if they get the same result? I'll post just the code so nobody has to convert from 2002 or 2003.

    VB Code:
    1. Public Class Test
    2.     Private _Name As String
    3.     Public ID As Integer = 0
    4.  
    5.     Public ReadOnly Property Name() As String
    6.         Get
    7.             Return _Name
    8.         End Get
    9.     End Property
    10.  
    11.     Public Sub Test()
    12.         Dim bf As Reflection.BindingFlags = Reflection.BindingFlags.Public
    13.         Dim fi As Reflection.FieldInfo
    14.         For Each fi In Me.GetType.GetFields(bf)
    15.             MsgBox(fi.Name, , "Worked WITH flags")
    16.         Next
    17.         For Each fi In Me.GetType.GetFields
    18.             MsgBox(fi.Name, , "Worked withOUT flags")
    19.         Next
    20.     End Sub
    21.  
    22. End Class
    23.  
    24. 'the test in a form on a button click or whatever
    25.         Dim t As New Test
    26.         t.Test()

    I only get one message box and there should be two. It seems that the GetFields, GetProperties, GetMembers methods used in reflection only work when no flags are passed to them. If you pass any BindingFlags in then it returns nothing all the time even though its oberloaded to take such.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Same result . One msgbox showing "ID" . I'm using VS.NET 2003 .

  3. #3

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well its not a bug after all. You have to include the Instance flag to get any results apparently. Thanks for testing Pirate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width