Statically-typed reflection with LINQ
Quite some time ago I posted about how to use LINQ to provide a strong-typed reflection API. I used a very old LINQ preview back then.
With .NET 3.5 and C# 3.0 released now, it was time for an update. As part of the update, I also improved the API a little bit. Usage now is:
MethodInfo toString = Reflect<object>.GetMethod(x => x.ToString());
The renamed Reflect<TTarget>
class receives the type you want to reflect as a generic parameter. Then you can use GetMethod
, GetField
or GetProperty...