Eric Lippert on infoof()
May 22, 2009 at 06:42 PM | categories: Uncategorized | View CommentsI previously mentioned some hypothetical C# fieldof
and methodof
operators, which would obtain FieldInfo
and MethodInfo
objects, in the same way that typeof
retrieves Type
at runtime.
Eric Lippert explains the pros and cons of a combined infoof
operator, which mainly centre around how hard it would be to pick the right method overload each time.
In the comments, Jonathan Pryor points out my favourite replacement for methodof
:
Fastest by far in my testing -- faster than string-based Reflection, in fact -- is Mike's "Poor's man infoof" using the Delegate.Method property. This effectively bypasses most of the Reflection infrastructure (no Type.GetMember(), etc.), and is the closest we can get to IL member lookup resolution.