.NET Reflection – Is Using Reflection Still ‘Bad’ or ‘Slow’?

netreflection

I've noticed when dealing with Expressions or Expression Trees I'm using reflection a lot to set and get values in properties and what have you. It has occurred to me that the use of reflection seems to be getting more and more common. Things like DataAnotations for validation, Attribute heavy ORMs, etc. Have me wondering: What has changed since the days years and years ago when I used to be told to avoid reflection if at all possible?

So what, if anything has changed? Is it just the speed of the machines? Have there been changes to the framework to speed up reflection?

Or has nothing really changed? Is it still "bad" or "slow" to use reflection?

Best Answer

Reflection is neither bad, nor slow. It is simply a tool. Like all tools, it is very valuable for certain scenarios, not so valuable for others.

If performance is really an issue, you can always use a library like FasterFlect.

Further Reading
If reflection is inefficient, when is it most appropriate?