Improving performance reflection - what alternatives should I consider?

前端 未结 6 1810
攒了一身酷
攒了一身酷 2020-12-01 05:29

I need to dynamically set values on a bunch or properties on an object, call it a transmission object.

There will be a fair number of these transmission objects that

6条回答
  •  猫巷女王i
    2020-12-01 06:07

    Reflection can be blazingly fast if you do it right (not as fast as static code, of course).

    Finding a property-setter is slow. Invoking a delegate is fast.

    You need to get and cache Delegate objects for each property-setter on each type of DTO. That's the slow part, but it's a one-time hit. Then you can Invoke each of the cached delegates for the property-setters of a given DTO type, passing in the DTO object and the new property value, but this part will be very fast.

提交回复
热议问题