Use throws expressions and expression bodied members (#10764)
This commit is contained in:
parent
b08577342d
commit
c18fc3d7ca
|
|
@ -212,12 +212,10 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public virtual ObjectResult StatusCode([ActionResultStatusCode] int statusCode, [ActionResultObjectValue] object value)
|
public virtual ObjectResult StatusCode([ActionResultStatusCode] int statusCode, [ActionResultObjectValue] object value)
|
||||||
{
|
{
|
||||||
var result = new ObjectResult(value)
|
return new ObjectResult(value)
|
||||||
{
|
{
|
||||||
StatusCode = statusCode
|
StatusCode = statusCode
|
||||||
};
|
};
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -270,13 +268,11 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public virtual ContentResult Content(string content, MediaTypeHeaderValue contentType)
|
public virtual ContentResult Content(string content, MediaTypeHeaderValue contentType)
|
||||||
{
|
{
|
||||||
var result = new ContentResult
|
return new ContentResult
|
||||||
{
|
{
|
||||||
Content = content,
|
Content = content,
|
||||||
ContentType = contentType?.ToString()
|
ContentType = contentType?.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1772,9 +1768,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <returns>The created <see cref="UnprocessableEntityResult"/> for the response.</returns>
|
/// <returns>The created <see cref="UnprocessableEntityResult"/> for the response.</returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public virtual UnprocessableEntityResult UnprocessableEntity()
|
public virtual UnprocessableEntityResult UnprocessableEntity()
|
||||||
{
|
=> new UnprocessableEntityResult();
|
||||||
return new UnprocessableEntityResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an <see cref="UnprocessableEntityObjectResult"/> that produces a <see cref="StatusCodes.Status422UnprocessableEntity"/> response.
|
/// 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>
|
/// <returns>The created <see cref="UnprocessableEntityObjectResult"/> for the response.</returns>
|
||||||
[NonAction]
|
[NonAction]
|
||||||
public virtual UnprocessableEntityObjectResult UnprocessableEntity([ActionResultObjectValue] object error)
|
public virtual UnprocessableEntityObjectResult UnprocessableEntity([ActionResultObjectValue] object error)
|
||||||
{
|
=> new UnprocessableEntityObjectResult(error);
|
||||||
return new UnprocessableEntityObjectResult(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an <see cref="UnprocessableEntityObjectResult"/> that produces a <see cref="StatusCodes.Status422UnprocessableEntity"/> response.
|
/// Creates an <see cref="UnprocessableEntityObjectResult"/> that produces a <see cref="StatusCodes.Status422UnprocessableEntity"/> response.
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public PhysicalFileResult(string fileName, MediaTypeHeaderValue contentType)
|
public PhysicalFileResult(string fileName, MediaTypeHeaderValue contentType)
|
||||||
: base(contentType?.ToString())
|
: base(contentType?.ToString())
|
||||||
{
|
{
|
||||||
if (fileName == null)
|
FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(fileName));
|
|
||||||
}
|
|
||||||
|
|
||||||
FileName = fileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -55,15 +50,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public string FileName
|
public string FileName
|
||||||
{
|
{
|
||||||
get => _fileName;
|
get => _fileName;
|
||||||
set
|
set => _fileName = value ?? throw new ArgumentNullException(nameof(value));
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
_fileName = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
|
/// <param name="type">The <see cref="Type"/> of object that is going to be written in the response.</param>
|
||||||
public ProducesAttribute(Type type)
|
public ProducesAttribute(Type type)
|
||||||
{
|
{
|
||||||
if (type == null)
|
Type = type ?? throw new ArgumentNullException(nameof(type));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
Type = type;
|
|
||||||
ContentTypes = new MediaTypeCollection();
|
ContentTypes = new MediaTypeCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <param name="statusCode">The HTTP response status code.</param>
|
/// <param name="statusCode">The HTTP response status code.</param>
|
||||||
public ProducesResponseTypeAttribute(Type type, int statusCode)
|
public ProducesResponseTypeAttribute(Type type, int statusCode)
|
||||||
{
|
{
|
||||||
if (type == null)
|
Type = type ?? throw new ArgumentNullException(nameof(type));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
Type = type;
|
|
||||||
StatusCode = statusCode;
|
StatusCode = statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <param name="template">The route template. May not be null.</param>
|
/// <param name="template">The route template. May not be null.</param>
|
||||||
public RouteAttribute(string template)
|
public RouteAttribute(string template)
|
||||||
{
|
{
|
||||||
if (template == null)
|
Template = template ?? throw new ArgumentNullException(nameof(template));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(template));
|
|
||||||
}
|
|
||||||
|
|
||||||
Template = template;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <param name="type">The <see cref="Type"/> of filter to find.</param>
|
/// <param name="type">The <see cref="Type"/> of filter to find.</param>
|
||||||
public ServiceFilterAttribute(Type type)
|
public ServiceFilterAttribute(Type type)
|
||||||
{
|
{
|
||||||
if (type == null)
|
ServiceType = type ?? throw new ArgumentNullException(nameof(type));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceType = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,9 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <param name="principal">The claims principal containing the user claims.</param>
|
/// <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>
|
/// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the sign-in operation.</param>
|
||||||
public SignInResult(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties)
|
public SignInResult(string authenticationScheme, ClaimsPrincipal principal, AuthenticationProperties properties)
|
||||||
{
|
{
|
||||||
if (authenticationScheme == null)
|
AuthenticationScheme = authenticationScheme ?? throw new ArgumentNullException(nameof(authenticationScheme));
|
||||||
{
|
Principal = principal ?? throw new ArgumentNullException(nameof(principal));
|
||||||
throw new ArgumentNullException(nameof(authenticationScheme));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (principal == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(principal));
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthenticationScheme = authenticationScheme;
|
|
||||||
Principal = principal;
|
|
||||||
Properties = properties;
|
Properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <param name="authenticationSchemes">The authentication scheme to use when signing out the user.</param>
|
/// <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>
|
/// <param name="properties"><see cref="AuthenticationProperties"/> used to perform the sign-out operation.</param>
|
||||||
public SignOutResult(IList<string> authenticationSchemes, AuthenticationProperties properties)
|
public SignOutResult(IList<string> authenticationSchemes, AuthenticationProperties properties)
|
||||||
{
|
{
|
||||||
if (authenticationSchemes == null)
|
AuthenticationSchemes = authenticationSchemes ?? throw new ArgumentNullException(nameof(authenticationSchemes));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(authenticationSchemes));
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthenticationSchemes = authenticationSchemes;
|
|
||||||
Properties = properties;
|
Properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// <param name="type">The <see cref="Type"/> of filter to create.</param>
|
/// <param name="type">The <see cref="Type"/> of filter to create.</param>
|
||||||
public TypeFilterAttribute(Type type)
|
public TypeFilterAttribute(Type type)
|
||||||
{
|
{
|
||||||
if (type == null)
|
ImplementationType = type ?? throw new ArgumentNullException(nameof(type));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
ImplementationType = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,7 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
public VirtualFileResult(string fileName, MediaTypeHeaderValue contentType)
|
public VirtualFileResult(string fileName, MediaTypeHeaderValue contentType)
|
||||||
: base(contentType?.ToString())
|
: base(contentType?.ToString())
|
||||||
{
|
{
|
||||||
if (fileName == null)
|
FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(fileName));
|
|
||||||
}
|
|
||||||
|
|
||||||
FileName = fileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -56,19 +51,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FileName
|
public string FileName
|
||||||
{
|
{
|
||||||
get
|
get => _fileName;
|
||||||
{
|
set => _fileName = value ?? throw new ArgumentNullException(nameof(value));
|
||||||
return _fileName;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
_fileName = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,9 @@ namespace Microsoft.Extensions.Internal
|
||||||
public PropertyActivator(
|
public PropertyActivator(
|
||||||
PropertyInfo propertyInfo,
|
PropertyInfo propertyInfo,
|
||||||
Func<TContext, object> valueAccessor)
|
Func<TContext, object> valueAccessor)
|
||||||
{
|
{
|
||||||
if (propertyInfo == null)
|
PropertyInfo = propertyInfo ?? throw new ArgumentNullException(nameof(propertyInfo));
|
||||||
{
|
_valueAccessor = valueAccessor ?? throw new ArgumentNullException(nameof(valueAccessor));
|
||||||
throw new ArgumentNullException(nameof(propertyInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valueAccessor == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(valueAccessor));
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertyInfo = propertyInfo;
|
|
||||||
_valueAccessor = valueAccessor;
|
|
||||||
_fastPropertySetter = PropertyHelper.MakeFastPropertySetter(propertyInfo);
|
_fastPropertySetter = PropertyHelper.MakeFastPropertySetter(propertyInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,4 +97,4 @@ namespace Microsoft.Extensions.Internal
|
||||||
return properties.Select(createActivateInfo).ToArray();
|
return properties.Select(createActivateInfo).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,8 @@ namespace Microsoft.Extensions.Internal
|
||||||
/// This constructor does not cache the helper. For caching, use <see cref="GetProperties(Type)"/>.
|
/// This constructor does not cache the helper. For caching, use <see cref="GetProperties(Type)"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PropertyHelper(PropertyInfo property)
|
public PropertyHelper(PropertyInfo property)
|
||||||
{
|
{
|
||||||
if (property == null)
|
Property = property ?? throw new ArgumentNullException(nameof(property));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(property));
|
|
||||||
}
|
|
||||||
|
|
||||||
Property = property;
|
|
||||||
Name = property.Name;
|
Name = property.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue