views:

208

answers:

3

I'm working on creating my own DI framework that creates delegate factories as a learning exercise. My way of building typed delegates is to use expressions to create a function that calls a static method with reference to my container and any constructor params.

This thrown up an interesting question with regards to value types. Which is the most performant:

a) Using reflection to select a static generic method with the correct number of parameters then use MakeGenericMethod to remove the generics

b) Go for the old fashion params Object[] and take the hit on boxing?

+14  A: 

IME, boxing time is nothing compared to reflection.

Otávio Décio
+4  A: 

I'd guess that reflection would be alot slower, probably orders of magintude so.

It's pretty easy to bench though, give it a go and post your results :)

Paul Creasey
+3  A: 

In this case, boxing will be orders of magnitude faster than reflection.

Of course, you could always cache the reflection results.

Bryan Watts