Assertfail

Using values in expression

20 Oct 2013

I’ve done some small tests while writing the library to handle readonly objects in c#. Turns out that getting the value of a sub expression can be costly (since you have to compile the expression and execute). When just setting one property there can be a performance benefit of using the following syntax:
<blockquote class="tr_bq">

new MyClass(1, "2").With(m => m.MyProperty, 3)

</blockquote> There might be some way of optimizing the code in order to get better performance for the form:
<blockquote class="tr_bq">

new MyClass(1, "2").With(m => m.MyProperty == 3)

</blockquote> If there are only a few usages then the performance hit is probably negligible.

Tags


Comments or errors? Fork this post and do a pull request on github