我在一个教程中碰到了下面的方法;
private async Task<ClaimsIdentity> GetClaimsIdentity(string userName, string password)
{
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
return await Task.FromResult<ClaimsIdentity>(null);
// get the user to verifty
var userToVerify = await _userManager.FindByNameAsync(userName);
if (userToVerify == null) return await Task.FromResult<ClaimsIdentity>(null);
// check the credentials
if (await _userManager.CheckPasswordAsync(userToVerify, password))
{
return await Task.FromResult(_jwtFactory.GenerateClaimsIdentity(userName, userToVerify.Id));
}
// Credentials are invalid, or account doesn't exist
return await Task.FromResult<ClaimsIdentity>(null);
}
作者总是使用
await Task.FromResult<ClaimsIdentity>(...)
private async Task<ClaimsIdentity> GetClaimsIdentity(string userName, string password)
{
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
return null;
// get the user to verifty
var userToVerify = await _userManager.FindByNameAsync(userName);
if (userToVerify == null) return null;
// check the credentials
if (await _userManager.CheckPasswordAsync(userToVerify, password))
{
return _jwtFactory.GenerateClaimsIdentity(userName, userToVerify.Id);
}
// Credentials are invalid, or account doesn't exist
return null;
}
都是编译的。这两种方法有什么区别(如果有的话)?有什么可以利用的吗
await Task.FromResult<ClaimsIdentity>(null)
以这种方式?