John Lam 1997 — 2026

Wish list for V2 System.Reflection

Over the past couple of years, I’ve become rather intimate with the various metadata API’s in the CLR. For some more info on this, see the slides for the Metadata Internals talk that I gave at last year’s WinSummit conference.

Interestingly enough, I find that the metadata API that I use the least is System.Reflection. This is due to the fact that the work that I do (mostly involving CIL instruction rewriting these days) simply cannot be done using the existing System.Reflection API’s. There’s a bunch of things that really need to be added to System.Reflection to make it useful for my purposes.[1] Here’s a short list:

  1. Given a MethodBase object, make it possible for me to retrieve the underlying MethodDef token that defines that method signature. You will also need a mechanism for mapping MethodRef’s to the appropriate MethodDef in the current App Domain.
  2. Given a MethodBase object, make it possible for me to retrieve the underlying CIL instructions.
  3. Given a MethodBase object, make it possible for me to rewrite the underlying CIL instructions. This is already possible via the Profiling API’s. It would be nice to be able to do all of this from managed code.
  4. Make it possible for me to create a MethodBase object from a MethodDef token. Obviously, scoping rules must apply, i.e. the factory that creates the MethodBase object must know what module the MethodDef token is scoped by.

If you have any more ideas about what should go on this list, send me some mail and I’ll add it to this list.

[1] Don’t get me wrong, System.Reflection and its companion, System.Reflection.Emit, are wonderful API’s if you use them for what they were intended. They are particularly useful if you want to build dynamic proxies. But that’s just not on my radar screen (and besides, its been done to death in the Java world … it’s time for something more innovative ;).