C#C
C#โ€ข2y ago
fasadin

Chaining async methods. Method not found

I want to have something like this

        var foo = await new UserBuilder(_client)
            .CreateUser()
            .VerifyUser()
            .Build();


but this gives me an error Cannot resolve symbol 'VerifyUser' it's because CreateUser returns Task<T>

if I write like this

       var foo = await new UserBuilder(_client)
            .CreateUser();
        foo = await asd.VerifyUser();
        var bar = await asd.Build();


or like this

var asd = await (await (await new UserBuilder(_grupieClient)
            .CreateUser())
            .VerifyUser())
            .Build();


then it works as expected

but second and third solution it's ugly.

How to achieve desired syntax?
Was this page helpful?