GetFields not working?

  • Thread starter Thread starter Jon Slaughter
  • Start date Start date
J

Jon Slaughter

FieldInfo[] fields = type.GetFields();

works and returns all public fields, but when I do

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



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



Thanks,

Jon
 
Jon Slaughter said:
FieldInfo[] fields = type.GetFields();

works and returns all public fields, but when I do

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

I get nothing!! Whats going on? (again, its that simple... if I delete
BindingFlags.Public 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.
 
Fredo said:
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
 
Jon Skeet said:
Jon Slaughter said:
FieldInfo[] fields = type.GetFields();

works and returns all public fields, but when I do

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

I get nothing!! Whats going on? (again, its that simple... if I delete
BindingFlags.Public 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top