Retrieving information about a field in a class.

  • Thread starter Thread starter Nathan Bullock
  • Start date Start date
N

Nathan Bullock

Hello Everyone,

Is there anyway to get the fieldinfo object for a specified field in a
class. Something better than telling what its name is, since this
isn't checked by the compiler.

Something maybe like this:

class Foo
{
public int foo;

public Foo()
{
FieldInfo fi = FieldInfo(foo);
// or fi = foo.Field();
Console.Writeline("{0}", fi.Name);
}
}

Nathan Bullock
 
Hello Nathan,

You can query a type instance for all fields it has, and then iterate
through the returned array of FieldInfo objects. But I'm afraid there's no
way to obtain the FieldInfo instance direct from a field variable like you
have suggested.
 

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