GetFields not working?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Slaughter

    GetFields not working?

    FieldInfo[] fields = type.GetFields( );

    works and returns all public fields, but when I do

    FieldInfo[] fields = type.GetFields( BindingFlags.Pu blic);



    I get nothing!! Whats going on? (again, its that simple... if I delete
    BindingFlags.Pu blic I get all public fields but if I don't then I get
    nothing)



    Thanks,

    Jon


  • Fredo

    #2
    Re: GetFields not working?

    You need to specify whether you want instance or static members by or'ing
    BindingFlags.

    I believe GetFields() does Public | Instance.



    "Jon Slaughter" <Jon_Slaughter@ Hotmail.comwrot e in message
    news:KIvIj.2435 0$Ej5.20483@new ssvr29.news.pro digy.net...
    FieldInfo[] fields = type.GetFields( );
    >
    works and returns all public fields, but when I do
    >
    FieldInfo[] fields = type.GetFields( BindingFlags.Pu blic);
    >
    >
    >
    I get nothing!! Whats going on? (again, its that simple... if I delete
    BindingFlags.Pu blic I get all public fields but if I don't then I get
    nothing)
    >
    >
    >
    Thanks,
    >
    Jon
    >
    >

    Comment

    • Jon Slaughter

      #3
      Re: GetFields not working?


      "Fredo" <fredo@hotmail. comwrote in message
      news:QfCdnQua-bAgFW_anZ2dnUVZ _uOmnZ2d@gigane ws.com...
      You need to specify whether you want instance or static members by or'ing
      BindingFlags.
      >
      I believe GetFields() does Public | Instance.
      >
      Thanks, that was the issue.

      Jon


      Comment

      • Jon Slaughter

        #4
        Re: GetFields not working?


        "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
        news:MPG.225c99 8db0fcbfe7c40@m snews.microsoft .com...
        Jon Slaughter <Jon_Slaughter@ Hotmail.comwrot e:
        >FieldInfo[] fields = type.GetFields( );
        >>
        >works and returns all public fields, but when I do
        >>
        >FieldInfo[] fields = type.GetFields( BindingFlags.Pu blic);
        >>
        >I get nothing!! Whats going on? (again, its that simple... if I delete
        >BindingFlags.P ublic I get all public fields but if I don't then I get
        >nothing)
        >
        Could you post a short but complete program which demonstrates the
        problem?
        >
        See http://www.pobox.com/~skeet/csharp/complete.html for details of
        what I mean by that.
        >
        See Fredo's reply.


        Comment

        Working...