When do you use reflection? Patterns/anti-patterns

前端 未结 17 2211
旧时难觅i
旧时难觅i 2020-12-02 09:58

I understand the reflection API (in c#) but I am not sure in what situation would I use it. What are some patterns - anti-patterns for using reflection?

17条回答
  •  既然无缘
    2020-12-02 10:49

    I use it in a binary serializer (protobuf-net). I use reflection only to build the model - when it is used (i.e. during [de]serialization) it is using delegates etc for maximum performance.

    I also used it (along with ComponentModel and Reflection.Emit) in HyperDescriptor, to build accelerated property access (~100x the speed of regular reflection).

    And by necessity, you need to use reflection if you are building your own Expressions.

提交回复
热议问题