Tsahi
Tsahi

Reputation: 455

Get property values without using reflection

I have a list which contains thousands of objects. I want to get the values of specific properties in each iteration, but I don't want to use reflection because of performance penalty. What other choices do I have?

Upvotes: 1

Views: 540

Answers (1)

Servy
Servy

Reputation: 203825

Have all of the objects in question implement an interface that exposes the properties you are interested in, and have a list of that interface type. This not only improves performance over reflection, but ensures static verification of type safety of your code.

Upvotes: 5

Related Questions