My Tech-Ed Talk: Deep Reflection - What's new & Hot in Reflection 2.0

My upcoming Tech-Ed Talk in Israel will be all about what’s new and Cool in .NET 2.0 Reflection. Over the coming weeks until TechEd, I’ll supply links and information detailing the stuff I’ll be talking about.

For the past three weeks or so I’ve been totally immersed in Reflection-Land.

There are seriously cool things going on behind the scenes, and, frankly,  I was surprised at the amount of new stuff that is now possible.

One of my favorite features is the new ability to reflection over a Method’s Body. That is, get the actually IL for the method in the form of a Byte Array. You can then parse the IL and do what ever you want with it (including building your own version of reflector, for example).

This is possible due to a new API added on the MethodBase class, called: “GetMethodBody()”. You can then use the resulting “MethodBody” object and invoke it’s “GetILAsByteArray()” method.

 

It’s really quite simple.

Parsing the Byte Array is a different matter, though. I’ll talk about that in a future post. For now, suffice to say that you can do wonderful things once you have the IL.

You can basically get the IL from any MethodInfo object at runtime and parse it (for security reasons, you might wanna make sure that there are no method calls to a specific method from any plugin you are about to load)

 

I was also able to create a MethodInfo Debugger Visualizer, based on the code released here by a guy from the Reflection team. His visualizer shows the IL for a DynamicMethod object at debug time (that’s also a new class I’ll talk about in a future post). It took me a day or so to figure out how to extend it to show the IL for any method info object during debugging, and it works quite well!

In fact, you can now write a method that writes its own code in IL J

 

All that and more, in the near future, I promise J

Meanwhile, here’s a nice post form Joel Pobar, highlighting some of the new features in Reflection 2.0. I’ll be elaborating on these more, but you can follow the links on his post as well to discover a whole new world of possibilities.

Cross Posted from Blogs.Microsoft.Co.Il/Blogs/Royo
Published Sunday, April 23, 2006 2:27 AM by RoyOsherove

Comments

Monday, April 24, 2006 11:02 AM by Amir

# re: My Tech-Ed Talk: Deep Reflection - What's new & Hot in Reflection 2.0

can u post your visualizer?
Monday, May 15, 2006 8:59 PM by Xanax

# Re: My Tech-Ed Talk: Deep Reflection - What's new & Hot in Reflection 2.0

Cool design, but very light. For each of thesemarks off a certain class of things for itself and busies itself aboutthis as about something existing and real,-not however qua real; thescience that does this is another distinct from these.
Saturday, May 27, 2006 6:36 AM by mattonsoftware.com

# .NET Resources

The following links to .NET resources have been collated over time with the assistance of colleagues. ...
Thursday, August 03, 2006 1:38 AM by Scott Hanselman's Computer Zen

# Hanselminutes Podcast 27 - Reflection

Thursday, August 03, 2006 7:35 AM by David's blog

# Note to Self: HanselMinutes #27: Reflection

Sunday, August 20, 2006 2:21 PM by Note to Self: HanselMinutes #27: Reflection at TR

# Note to Self: HanselMinutes #27: Reflection at TR