Use throws expressions and expression bodied members (#10764)

This commit is contained in:
YPTopMan 2019-06-07 00:56:12 +08:00 committed by Pranav K
parent b08577342d
commit c18fc3d7ca
12 changed files with 26 additions and 118 deletions

View File

@ -212,12 +212,10 @@ namespace Microsoft.AspNetCore.Mvc
[NonAction]
public virtual ObjectResult StatusCode([ActionResultStatusCode] int statusCode, [ActionResultObjectValue] object value)
{
var result = new ObjectResult(value)
return new ObjectResult(value)
{
StatusCode = statusCode
};
return result;
}
/// <summary>
@ -270,13 +268,11 @@ namespace Microsoft.AspNetCore.Mvc
[NonAction]
public virtual ContentResult Content(string content, MediaTypeHeaderValue contentType)
{
var result = new ContentResult
return new ContentResult
{
Content = content,
ContentType = contentType?.ToString()
};
return result;
}
/// <summary>
@ -1772,9 +1768,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <returns>The created <see cref="UnprocessableEntityResult"/> for the response.</returns>
[NonAction]
public virtual UnprocessableEntityResult UnprocessableEntity()
{
return new UnprocessableEntityResult();
}
=> new UnprocessableEntityResult();
/// <summary>
/// Creates an <see cref="UnprocessableEntityObjectResult"/> that produces a <see cref="StatusCodes.Status422UnprocessableEntity"/> response.
@ -1783,9 +1777,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <returns>The created <see cref="UnprocessableEntityObjectResult"/> for the response.</returns>
[NonAction]
public virtual UnprocessableEntityObjectResult UnprocessableEntity([ActionResultObjectValue] object error)
{
return new UnprocessableEntityObjectResult(error);
}
=> new UnprocessableEntityObjectResult(error);
/// <summary>
/// Creates an <see cref="UnprocessableEntityObjectResult"/> that produces a <see cref="StatusCodes.Status422UnprocessableEntity"/> response.

View File

@ -41,12 +41,7 @@ namespace Microsoft.AspNetCore.Mvc
public PhysicalFileResult(string fileName, MediaTypeHeaderValue contentType)
: base(contentType?.ToString())
{
if (fileName == null)
{
throw new ArgumentNullException(nameof(fileName));
}
FileName = fileName;
FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
}
/// <summary>
@ -55,15 +50,7 @@ namespace Microsoft.AspNetCore.Mvc
public string FileName
{
get => _fileName;
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_fileName = value;
}
set => _fileName = value ?? throw new ArgumentNullException(nameof(value));
}
/// <inheritdoc />

View File

@ -25,13 +25,8 @@ namespace Microsoft.AspNetCore.Mvc
/// </summary>
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
public ProducesAttribute(Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
Type = type;
{
Type = type ?? throw new ArgumentNullException(nameof(type));
ContentTypes = new MediaTypeCollection();
}

View File

@ -29,12 +29,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="statusCode">The HTTP response status code.</param>
public ProducesResponseTypeAttribute(Type type, int statusCode)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
Type = type;
Type = type ?? throw new ArgumentNullException(nameof(type));
StatusCode = statusCode;
}

View File

@ -20,12 +20,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="template">The route template. May not be null.</param>
public RouteAttribute(string template)
{
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
Template = template;
Template = template ?? throw new ArgumentNullException(nameof(template));
}
/// <inheritdoc />

View File

@ -30,12 +30,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="type">The <see cref="Type"/> of filter to find.</param>
public ServiceFilterAttribute(Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
ServiceType = type;
ServiceType = type ?? throw new ArgumentNullException(nameof(type));
}
/// <inheritdoc />

View File

@ -35,19 +35,9 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="principal">The claims principal containing the user claims.</param>
/// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the sign-in operation.</param>
public SignInResult(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties)
{
if (authenticationScheme == null)
{
throw new ArgumentNullException(nameof(authenticationScheme));
}
if (principal == null)
{
throw new ArgumentNullException(nameof(principal));
}
AuthenticationScheme = authenticationScheme;
Principal = principal;
{
AuthenticationScheme = authenticationScheme ?? throw new ArgumentNullException(nameof(authenticationScheme));
Principal = principal ?? throw new ArgumentNullException(nameof(principal));
Properties = properties;
}

View File

@ -62,13 +62,8 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="authenticationSchemes">The authentication scheme to use when signing out the user.</param>
/// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the sign-out operation.</param>
public SignOutResult(IList<string> authenticationSchemes, AuthenticationProperties properties)
{
if (authenticationSchemes == null)
{
throw new ArgumentNullException(nameof(authenticationSchemes));
}
AuthenticationSchemes = authenticationSchemes;
{
AuthenticationSchemes = authenticationSchemes ?? throw new ArgumentNullException(nameof(authenticationSchemes));
Properties = properties;
}

View File

@ -34,12 +34,7 @@ namespace Microsoft.AspNetCore.Mvc
/// <param name="type">The <see cref="Type"/> of filter to create.</param>
public TypeFilterAttribute(Type type)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
ImplementationType = type;
ImplementationType = type ?? throw new ArgumentNullException(nameof(type));
}
/// <summary>

View File

@ -43,12 +43,7 @@ namespace Microsoft.AspNetCore.Mvc
public VirtualFileResult(string fileName, MediaTypeHeaderValue contentType)
: base(contentType?.ToString())
{
if (fileName == null)
{
throw new ArgumentNullException(nameof(fileName));
}
FileName = fileName;
FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
}
/// <summary>
@ -56,19 +51,8 @@ namespace Microsoft.AspNetCore.Mvc
/// </summary>
public string FileName
{
get
{
return _fileName;
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_fileName = value;
}
get => _fileName;
set => _fileName = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>

View File

@ -15,19 +15,9 @@ namespace Microsoft.Extensions.Internal
public PropertyActivator(
PropertyInfo propertyInfo,
Func<TContext, object> valueAccessor)
{
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
if (valueAccessor == null)
{
throw new ArgumentNullException(nameof(valueAccessor));
}
PropertyInfo = propertyInfo;
_valueAccessor = valueAccessor;
{
PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo));
_valueAccessor = valueAccessor ?? throw new ArgumentNullException(nameof(valueAccessor));
_fastPropertySetter = PropertyHelper.MakeFastPropertySetter(propertyInfo);
}
@ -107,4 +97,4 @@ namespace Microsoft.Extensions.Internal
return properties.Select(createActivateInfo).ToArray();
}
}
}
}

View File

@ -51,13 +51,8 @@ namespace Microsoft.Extensions.Internal
/// This constructor does not cache the helper. For caching, use <see cref="GetProperties(Type)"/>.
/// </summary>
public PropertyHelper(PropertyInfo property)
{
if (property == null)
{
throw new ArgumentNullException(nameof(property));
}
Property = property;
{
Property = property ?? throw new ArgumentNullException(nameof(property));
Name = property.Name;
}