I have a class in C# with a public member. For example:
public class Foo
{
public int Bar;
}
I'd like to get the FieldInfo for Bar, without having to do:
return this.GetType().GetField("Bar");
I'm just looking for a cleaner, shorter way to do this. Something like:
return field(Bar);
I could, of course, build a method:
public FieldInfo field(string name)
{
return this.GetType().GetField(name);
}
I was just wondering if C# had something built-in for this sort of code. Something that would check at compile-time, since the above method will cause a run-time error if I misspell the field's name.
Thank you!