Is there a C# equivalent of typeof for properties/methods/members?

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-03-19T15:58:09Z Indexed on 2010/03/19 16:01 UTC
Read the original article Hit count: 172

Filed under:
|
|

A classes Type metadata can be obtained in several ways. Two of them are:

var typeInfo = Type.GetType("MyClass")

and

var typeInfo = typeof(MyClass)

The advantage of the second way is that typos will be caught by the compiler, and the IDE can understand what I'm talking about (allowing features like refactoring to work without silently breaking the code)

Does there exist an equivalent way of strongly referencing members/properties/methods for metadata and reflection? Can I replace:

var propertyInfo = typeof(MyClass).GetProperty("MyProperty")

with something like:

var propertyInfo = property(MyClass.MyProperty)

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection