Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I respectually disagree with the notion that link extension methods should be side-effect free (not only because they aren't, any delegate can perform side effects).</p> <p>Consider the following:</p> <pre><code> public class Element {} public Enum ProcessType { This = 0, That = 1, SomethingElse = 2 } public class Class1 { private Dictionary&lt;ProcessType, Action&lt;Element&gt;&gt; actions = new Dictionary&lt;ProcessType,Action&lt;Element&gt;&gt;(); public Class1() { actions.Add( ProcessType.This, DoThis ); actions.Add( ProcessType.That, DoThat ); actions.Add( ProcessType.SomethingElse, DoSomethingElse ); } // Element actions: // This example defines 3 distict actions // that can be applied to individual elements, // But for the sake of the argument, make // no assumption about how many distict // actions there may, and that there could // possibly be many more. public void DoThis( Element element ) { // Do something to element } public void DoThat( Element element ) { // Do something to element } public void DoSomethingElse( Element element ) { // Do something to element } public void Apply( ProcessType processType, IEnumerable&lt;Element&gt; elements ) { Action&lt;Element&gt; action = null; if( ! actions.TryGetValue( processType, out action ) ) throw new ArgumentException("processType"); foreach( element in elements ) action(element); } } </code></pre> <p>What the example shows is really just a kind of late-binding that allows one invoke one of many possible actions having side-effects on a sequence of elements, without having to write a big switch construct to decode the value that defines the action and translate it into its corresponding method.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload