Setting data through reflection; SetValue

In C#/.NET, you can set data from an object using reflection which can be useful for things like mapping and testing. Typically, you’d use direct access, but reflection allows you to set data to fields and properties that you were un-aware of at compile time. This can save you a lot of code. But what are the performance implications?

Turns out that setting data directly from a property or field is 60-150 times faster than using the “SetValue” method.

Also note that the “Reflection Field Accessor” is way faster (6.3 times) than the “Reflection Property Accessor”! So accessing fields through reflection is much faster than accessing properties through reflection, but both are much slower than direct access.