Last active
August 27, 2024 19:33
-
-
Save KyleMit/ad2ce77f32d38eb0079a2bdb030191f4 to your computer and use it in GitHub Desktop.
await Task.WhenAll multiple conditional methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update in Method | |
public static async Task<Person> GetPersonAsync() | |
{ | |
var model = new Person(); | |
await Task.WhenAll( | |
UpdateFirstName(model), | |
UpdateLastName(model), | |
UpdateAge(model) | |
); | |
return model; | |
} | |
public static async Task UpdateFirstName(Person model) { | |
if (!model.ShowFirstName) { return; } | |
model.FirstName = await GetFirstNameAsync(); | |
} | |
public static async Task UpdateLastName(Person model) { | |
if (!model.ShowLastName) { return; } | |
model.LastName = await GetLastNameAsync(); | |
} | |
public static async Task UpdateAge(Person model) { | |
if (!model.ShowAge) { return; } | |
model.Age = await GetAgeAsync(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment