Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Reflection question

Reflection question

Scheduled Pinned Locked Moved Visual Basic
data-structuresquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    I try to use reflection to get a list of member fields in a form class.

    Public Class BaseForm
    Inherits System.Windows.Forms.Form
    ......
    Friend WithEvents MnuBaseFile As System.Windows.Forms.MenuItem
    Friend WithEvents MnuBaseWindow As System.Windows.Forms.MenuItem
    Friend WithEvents MnuBaseFileExit As System.Windows.Forms.MenuItem
    Friend WithEvents BaseFormTimer As System.Timers.Timer
    Friend WithEvents MenuMainSeparator1 As System.Windows.Forms.MenuItem
    Friend WithEvents HelpProvider As System.Windows.Forms.HelpProvider

    .....
    Dim fi As System.Reflection.FieldInfo() = My.Forms.BaseForm.GetType().GetFields()

    But I failed, the length of fi is zero, the fi is empty array.

    W 1 Reply Last reply
    0
    • E econy

      I try to use reflection to get a list of member fields in a form class.

      Public Class BaseForm
      Inherits System.Windows.Forms.Form
      ......
      Friend WithEvents MnuBaseFile As System.Windows.Forms.MenuItem
      Friend WithEvents MnuBaseWindow As System.Windows.Forms.MenuItem
      Friend WithEvents MnuBaseFileExit As System.Windows.Forms.MenuItem
      Friend WithEvents BaseFormTimer As System.Timers.Timer
      Friend WithEvents MenuMainSeparator1 As System.Windows.Forms.MenuItem
      Friend WithEvents HelpProvider As System.Windows.Forms.HelpProvider

      .....
      Dim fi As System.Reflection.FieldInfo() = My.Forms.BaseForm.GetType().GetFields()

      But I failed, the length of fi is zero, the fi is empty array.

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      The GetFields method with no parameters returns only public fields. Try using the other overload and specifying what you want to search for by defining the binding flags. For example:

      Dim fi As System.Reflection.FieldInfo() = My.Forms.BaseForm.GetType().GetFields(BindingFlags.NonPublic Or BindingFlags.Instance)

      For more information, see: Type.GetFields Method (BindingFlags)[^] and BindingFlags Enumeration[^]

      E 1 Reply Last reply
      0
      • W Wendelius

        The GetFields method with no parameters returns only public fields. Try using the other overload and specifying what you want to search for by defining the binding flags. For example:

        Dim fi As System.Reflection.FieldInfo() = My.Forms.BaseForm.GetType().GetFields(BindingFlags.NonPublic Or BindingFlags.Instance)

        For more information, see: Type.GetFields Method (BindingFlags)[^] and BindingFlags Enumeration[^]

        E Offline
        E Offline
        econy
        wrote on last edited by
        #3

        Thanks

        W 1 Reply Last reply
        0
        • E econy

          Thanks

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          You're welcome :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups