7

Is there a way to refactor this line

var result = (await Foo()).Bar()

So that it doesn't use parentheses and don't assign await result to temp variable?

I'm trying to build a fluent framework that supports long operations and real world code turns pretty ugly when you need to enclose await in parentheses:

var result = (await collection
    .TransformElements()
    .FetchData())
    .ProcessResults()
    .Aggregate();
Poma
  • 8,174
  • 18
  • 82
  • 144
  • any particular reason you don't like the temp variable approach? it would be very clean and obvious. IMO much cleaner than a huge single expression... Minor note: I wonder if `FetchData()` should be `FetchDataAsync()` – Marc Gravell Jun 25 '17 at 09:21
  • 2
    Possible duplicate of [How to make a fluent async inferface in C#](https://stackoverflow.com/questions/32112418/how-to-make-a-fluent-async-inferface-in-c-sharp) – Peter Bons Jun 25 '17 at 09:25

0 Answers0