Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Which is the most optimal way to get or set the value of a property using reflection

What is the most optimal way to repeatedly get or set the value of a property using reflection in a long-term perspective?

I tried using plain old reflection but this solution seems a little bit slow to me. I need another solution.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are correct! Reflection (in its natural form) is not a performant solution. However, I can suggest using pre-compiled expressions because they are way more efficient and by using them you can benefit from type safety. You can read more about the idea in this article on Medium.

You can also check out a library that I contribute to – TryAtSoftware.Extensions.Reflection. It exposes extension methods that can help construct appropriate expressions. It is open-source and available as a NuGet package.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading