If you have an interface with two implementations (one that is truly async and the other that is synchronous) this is what it would look like for each implementation - with both returning a Task<bool>
.
public interface IUserManager
{
Task<bool> IsUserInRole(string roleName);
}
public class UserManager1 : IUserManager
{
public async Task<bool> IsUserInRole(string roleName)
{
return await _userManager.IsInRoleAsync(_profile.Id, roleName);
}
}
public class UserManager2 : IUserManager
{
public Task<bool> IsUserInRole(string roleName)
{
return Task.FromResult(Roles.IsUserInRole(roleName));
}
}
If it is a void method you need to return Task.CompletedTask;
from the non async method
(I think .NET 4.5 and later)
See also : Return Task<bool> instantly