title: reuse a method call inside Func/lambda expression
body: <p>First let me say I'm not sure if the title of this question makes any sense, but I'm not sure how to word my problem.</p>
  
  <p>I have a class defined as</p>
  
  <pre><code>public static class NaturalSort&lt;T&gt;
  </code></pre>
  
  <p>This class has a method</p>
  
  <pre><code>public static IEnumerable&lt;T&gt; Sort(IEnumerable&lt;T&gt; list, Func&lt;T, String&gt; field)
  </code></pre>
  
  <p>Basically it performs a natural sort on some list given a Func that returns the value to sort on. I've been using this for anything that I want to do a natural sort on.</p>
  
  <p>Normally I would do something like </p>
  
  <pre><code>sorted = NaturalSort&lt;Thing&gt;.sort(itemList, item =&gt; item.StringValueToSortOn)
  </code></pre>
  
  <p>Now I have a case where the value I want to sort on isn't a field of the item, but is a call to some method</p>
  
  <p>Something like</p>
  
  <pre><code>sorted = NaturalSort&lt;Thing&gt;.sort(itemList, item =&gt; getValue(item))
  </code></pre>
  
  <p>Now what if I getValue returns an object instead of a string. and I need to do some conditional logic to get to my string value</p>
  
  <pre><code>sorted = NaturalSort&lt;Thing&gt;.sort(itemList, item =&gt; getValue(item).Something == null ? getValue(item).SomethingElse : getValue(item).SomeotherThing)
  </code></pre>
  
  <p>This would work, except the call to getValue is expensive and I don't want to call it 3 times. Is there some way I can call it once inside the expression?</p>