C# equivalent of typeof for fields

Posted by rwallace on Stack Overflow See other posts from Stack Overflow or by rwallace
Published on 2010-05-05T22:54:04Z Indexed on 2010/05/05 22:58 UTC
Read the original article Hit count: 120

Filed under:
|
|

With reflection, you can look up a class from a string at run time, but you can also say typeof(Foo) and get compile time type checking, auto completion etc.

If what you want is a field not a class, you can look it up from a string at runtime, but if you want compile time type checking etc., is there anyway to say something like fieldof(Foo.Bar)? I know the name of both the class and the field in advance, and I want to be able to refer to the field at compile time rather than with a run-time string lookup.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET