Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat fluent interfaces have you made or seen in C# that were very valuable? What was so great about them?
    text
    copied!<p>"Fluent interfaces" is a fairly hot topic these days. C# 3.0 has some nice features (particularly extension methods) that help you make them. </p> <p>FYI, a fluent API means that each method call returns something useful, often the same object you called the method on, so you can keep chaining things. Martin Fowler discusses it with a Java example <a href="http://www.martinfowler.com/bliki/FluentInterface.html" rel="nofollow noreferrer">here</a>. The concept kooks something like this:</p> <pre><code>var myListOfPeople = new List&lt;Person&gt;(); var person = new Person(); person.SetFirstName("Douglas").SetLastName("Adams").SetAge(42).AddToList(myListOfPeople); </code></pre> <p>I have seen some incredibly useful fluent interfaces in C# (one example is the fluent approach for validating parameters found in <a href="https://stackoverflow.com/questions/669678/what-is-the-smoothest-most-appealing-syntax-youve-found-for-asserting-parameter/670484#670484">an earlier StackOverflow question I had asked</a>. It blew me away. It was able to give highly readable syntax for expressing parameter validation rules, and also, if there were no exceptions, it was able to avoid instantiating any objects! So for the "normal case", there was very little overhead. This one tidbit taught me a <strong>huge</strong> amount in a short time. I want to find more things like that).</p> <p>So, I'd like to learn more by looking at and discussing some excellent examples. So, <strong>what are some excellent fluent interfaces you've made or seen in C#, and what made them so valuable?</strong></p> <p>Thanks.</p>
 

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