Smalltalk supports a syntax feature called “message cascades”. Cascades are being adopted by the Dart Programming language.
As far as I know, C# doesn’t support this. Were they ever considered during the design of the language? Is it conceivable that they could appear in a future version of the language?
2
Fluent interfaces are easily supported in C# by using return
this
.
In Linq, extension methods are used to accomplish the same thing. Extension methods over IQueryable
or IEnumerable
are easily chained together.
Cascades, as described by the page at the link you provided, seem to be merely a subtle refinement of an ordinary Fluent Interface where return
this
is not required to make it work, as all method calls beginning with ..
refer to the first returned result:
query('#my-form').query('button')
..classes.add('toggle')
..text = 'Click Me!'
..labels.add(toggleLabel);
Does C# support this? No, not exactly. But you can still write the following equivalent code:
var result = query('#my-form').query('button')
result.classes.add('toggle')
result.text = 'Click Me!'
result.labels.add(toggleLabel);
and it is only slightly more verbose (and arguably easier to read).
As to the question, “Were they ever considered for C#,” you would have to ask Anders Hejlsberg or Eric Lippert about that. My guess is that they view it as syntactic sugar, which in fact it is.
1