From 324db455d90f2833a452f7bab4236b1ce260967d Mon Sep 17 00:00:00 2001 From: Charlie Daly Date: Thu, 21 Sep 2017 20:23:04 +0100 Subject: [PATCH] ControllerBase helpers refactored with lambda syntax. - Addresses #6864 --- .../ControllerBase.cs | 240 +++++------------- 1 file changed, 60 insertions(+), 180 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs b/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs index 692627c6e8..0305f8e14e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs @@ -201,9 +201,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created object for the response. [NonAction] public virtual StatusCodeResult StatusCode(int statusCode) - { - return new StatusCodeResult(statusCode); - } + => new StatusCodeResult(statusCode); /// /// Creates a object by specifying a and @@ -228,9 +226,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created object for the response. [NonAction] public virtual ContentResult Content(string content) - { - return Content(content, (MediaTypeHeaderValue)null); - } + => Content(content, (MediaTypeHeaderValue)null); /// /// Creates a object with by specifying a @@ -241,9 +237,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created object for the response. [NonAction] public virtual ContentResult Content(string content, string contentType) - { - return Content(content, MediaTypeHeaderValue.Parse(contentType)); - } + => Content(content, MediaTypeHeaderValue.Parse(contentType)); /// /// Creates a object with by specifying a @@ -291,9 +285,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created object for the response. [NonAction] public virtual NoContentResult NoContent() - { - return new NoContentResult(); - } + => new NoContentResult(); /// /// Creates a object that produces an empty response. @@ -301,9 +293,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual OkResult Ok() - { - return new OkResult(); - } + => new OkResult(); /// /// Creates an object that produces an response. @@ -312,9 +302,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual OkObjectResult Ok(object value) - { - return new OkObjectResult(value); - } + => new OkObjectResult(value); /// /// Creates a object that redirects () @@ -482,9 +470,7 @@ namespace Microsoft.AspNetCore.Mvc /// [NonAction] public virtual RedirectToActionResult RedirectToAction() - { - return RedirectToAction(actionName: null); - } + => RedirectToAction(actionName: null); /// /// Redirects () to the specified action using the . @@ -493,9 +479,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction(string actionName) - { - return RedirectToAction(actionName, routeValues: null); - } + => RedirectToAction(actionName, routeValues: null); /// /// Redirects () to the specified action using the @@ -506,9 +490,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction(string actionName, object routeValues) - { - return RedirectToAction(actionName, controllerName: null, routeValues: routeValues); - } + => RedirectToAction(actionName, controllerName: null, routeValues: routeValues); /// /// Redirects () to the specified action using the @@ -519,9 +501,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction(string actionName, string controllerName) - { - return RedirectToAction(actionName, controllerName, routeValues: null); - } + => RedirectToAction(actionName, controllerName, routeValues: null); /// /// Redirects () to the specified action using the specified @@ -536,9 +516,7 @@ namespace Microsoft.AspNetCore.Mvc string actionName, string controllerName, object routeValues) - { - return RedirectToAction(actionName, controllerName, routeValues, fragment: null); - } + => RedirectToAction(actionName, controllerName, routeValues, fragment: null); /// /// Redirects () to the specified action using the specified @@ -553,9 +531,7 @@ namespace Microsoft.AspNetCore.Mvc string actionName, string controllerName, string fragment) - { - return RedirectToAction(actionName, controllerName, routeValues: null, fragment: fragment); - } + => RedirectToAction(actionName, controllerName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified action using the specified , @@ -617,9 +593,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent(string actionName) - { - return RedirectToActionPermanent(actionName, routeValues: null); - } + => RedirectToActionPermanent(actionName, routeValues: null); /// /// Redirects () to the specified action with @@ -631,9 +605,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent(string actionName, object routeValues) - { - return RedirectToActionPermanent(actionName, controllerName: null, routeValues: routeValues); - } + => RedirectToActionPermanent(actionName, controllerName: null, routeValues: routeValues); /// /// Redirects () to the specified action with @@ -645,9 +617,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent(string actionName, string controllerName) - { - return RedirectToActionPermanent(actionName, controllerName, routeValues: null); - } + => RedirectToActionPermanent(actionName, controllerName, routeValues: null); /// /// Redirects () to the specified action with @@ -663,9 +633,7 @@ namespace Microsoft.AspNetCore.Mvc string actionName, string controllerName, string fragment) - { - return RedirectToActionPermanent(actionName, controllerName, routeValues: null, fragment: fragment); - } + => RedirectToActionPermanent(actionName, controllerName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified action with @@ -681,9 +649,7 @@ namespace Microsoft.AspNetCore.Mvc string actionName, string controllerName, object routeValues) - { - return RedirectToActionPermanent(actionName, controllerName, routeValues, fragment: null); - } + => RedirectToActionPermanent(actionName, controllerName, routeValues, fragment: null); /// /// Redirects () to the specified action with @@ -750,9 +716,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(string routeName) - { - return RedirectToRoute(routeName, routeValues: null); - } + => RedirectToRoute(routeName, routeValues: null); /// /// Redirects () to the specified route using the specified . @@ -761,9 +725,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(object routeValues) - { - return RedirectToRoute(routeName: null, routeValues: routeValues); - } + => RedirectToRoute(routeName: null, routeValues: routeValues); /// /// Redirects () to the specified route using the specified @@ -774,9 +736,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(string routeName, object routeValues) - { - return RedirectToRoute(routeName, routeValues, fragment: null); - } + => RedirectToRoute(routeName, routeValues, fragment: null); /// /// Redirects () to the specified route using the specified @@ -787,9 +747,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(string routeName, string fragment) - { - return RedirectToRoute(routeName, routeValues: null, fragment: fragment); - } + => RedirectToRoute(routeName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified route using the specified @@ -845,9 +803,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName) - { - return RedirectToRoutePermanent(routeName, routeValues: null); - } + => RedirectToRoutePermanent(routeName, routeValues: null); /// /// Redirects () to the specified route with @@ -857,9 +813,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(object routeValues) - { - return RedirectToRoutePermanent(routeName: null, routeValues: routeValues); - } + => RedirectToRoutePermanent(routeName: null, routeValues: routeValues); /// /// Redirects () to the specified route with @@ -871,9 +825,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName, object routeValues) - { - return RedirectToRoutePermanent(routeName, routeValues, fragment: null); - } + => RedirectToRoutePermanent(routeName, routeValues, fragment: null); /// /// Redirects () to the specified route with @@ -885,9 +837,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName, string fragment) - { - return RedirectToRoutePermanent(routeName, routeValues: null, fragment: fragment); - } + => RedirectToRoutePermanent(routeName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified route with @@ -1061,9 +1011,7 @@ namespace Microsoft.AspNetCore.Mvc string pageHandler, object routeValues, string fragment) - { - return new RedirectToPageResult(pageName, pageHandler, routeValues, permanent: true, fragment: fragment); - } + => new RedirectToPageResult(pageName, pageHandler, routeValues, permanent: true, fragment: fragment); /// /// Redirects () to the specified page with @@ -1138,9 +1086,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType) - { - return File(fileContents, contentType, fileDownloadName: null); - } + => File(fileContents, contentType, fileDownloadName: null); /// /// Returns a file with the specified as content (), the @@ -1154,9 +1100,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName) - { - return new FileContentResult(fileContents, contentType) { FileDownloadName = fileDownloadName }; - } + => new FileContentResult(fileContents, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns a file with the specified as content (), @@ -1213,9 +1157,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType) - { - return File(fileStream, contentType, fileDownloadName: null); - } + => File(fileStream, contentType, fileDownloadName: null); /// /// Returns a file in the specified () with the @@ -1230,9 +1172,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName) - { - return new FileStreamResult(fileStream, contentType) { FileDownloadName = fileDownloadName }; - } + => new FileStreamResult(fileStream, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns a file in the specified (), @@ -1289,9 +1229,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType) - { - return File(virtualPath, contentType, fileDownloadName: null); - } + => File(virtualPath, contentType, fileDownloadName: null); /// /// Returns the file specified by () with the @@ -1306,9 +1244,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, string fileDownloadName) - { - return new VirtualFileResult(virtualPath, contentType) { FileDownloadName = fileDownloadName }; - } + => new VirtualFileResult(virtualPath, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns the file specified by (), and the @@ -1365,9 +1301,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType) - { - return PhysicalFile(physicalPath, contentType, fileDownloadName: null); - } + => PhysicalFile(physicalPath, contentType, fileDownloadName: null); /// /// Returns the file specified by () with the @@ -1385,9 +1319,7 @@ namespace Microsoft.AspNetCore.Mvc string physicalPath, string contentType, string fileDownloadName) - { - return new PhysicalFileResult(physicalPath, contentType) { FileDownloadName = fileDownloadName }; - } + => new PhysicalFileResult(physicalPath, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns the file specified by (), and @@ -1439,9 +1371,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual UnauthorizedResult Unauthorized() - { - return new UnauthorizedResult(); - } + => new UnauthorizedResult(); /// /// Creates an that produces a response. @@ -1449,9 +1379,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual NotFoundResult NotFound() - { - return new NotFoundResult(); - } + => new NotFoundResult(); /// /// Creates an that produces a response. @@ -1459,9 +1387,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual NotFoundObjectResult NotFound(object value) - { - return new NotFoundObjectResult(value); - } + => new NotFoundObjectResult(value); /// /// Creates an that produces a response. @@ -1469,9 +1395,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual BadRequestResult BadRequest() - { - return new BadRequestResult(); - } + => new BadRequestResult(); /// /// Creates an that produces a response. @@ -1479,9 +1403,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual BadRequestObjectResult BadRequest(object error) - { - return new BadRequestObjectResult(error); - } + => new BadRequestObjectResult(error); /// /// Creates an that produces a response. @@ -1583,9 +1505,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual CreatedAtActionResult CreatedAtAction(string actionName, object value) - { - return CreatedAtAction(actionName, routeValues: null, value: value); - } + => CreatedAtAction(actionName, routeValues: null, value: value); /// /// Creates a object that produces a response. @@ -1596,9 +1516,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual CreatedAtActionResult CreatedAtAction(string actionName, object routeValues, object value) - { - return CreatedAtAction(actionName, controllerName: null, routeValues: routeValues, value: value); - } + => CreatedAtAction(actionName, controllerName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces a response. @@ -1614,9 +1532,7 @@ namespace Microsoft.AspNetCore.Mvc string controllerName, object routeValues, object value) - { - return new CreatedAtActionResult(actionName, controllerName, routeValues, value); - } + => new CreatedAtActionResult(actionName, controllerName, routeValues, value); /// /// Creates a object that produces a response. @@ -1626,9 +1542,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual CreatedAtRouteResult CreatedAtRoute(string routeName, object value) - { - return CreatedAtRoute(routeName, routeValues: null, value: value); - } + => CreatedAtRoute(routeName, routeValues: null, value: value); /// /// Creates a object that produces a response. @@ -1638,9 +1552,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual CreatedAtRouteResult CreatedAtRoute(object routeValues, object value) - { - return CreatedAtRoute(routeName: null, routeValues: routeValues, value: value); - } + => CreatedAtRoute(routeName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces a response. @@ -1651,9 +1563,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual CreatedAtRouteResult CreatedAtRoute(string routeName, object routeValues, object value) - { - return new CreatedAtRouteResult(routeName, routeValues, value); - } + => new CreatedAtRouteResult(routeName, routeValues, value); /// /// Creates a object that produces an response. @@ -1661,9 +1571,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedResult Accepted() - { - return new AcceptedResult(); - } + => new AcceptedResult(); /// /// Creates a object that produces an response. @@ -1672,9 +1580,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(object value) - { - return new AcceptedResult(location: null, value: value); - } + => new AcceptedResult(location: null, value: value); /// /// Creates a object that produces an response. @@ -1701,9 +1607,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(string uri) - { - return new AcceptedResult(location: uri, value: null); - } + => new AcceptedResult(location: uri, value: null); /// /// Creates a object that produces an response. @@ -1713,9 +1617,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(string uri, object value) - { - return new AcceptedResult(uri, value); - } + => new AcceptedResult(uri, value); /// /// Creates a object that produces an response. @@ -1741,9 +1643,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName) - { - return AcceptedAtAction(actionName, routeValues: null, value: null); - } + => AcceptedAtAction(actionName, routeValues: null, value: null); /// /// Creates a object that produces an response. @@ -1753,9 +1653,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, string controllerName) - { - return AcceptedAtAction(actionName, controllerName, routeValues: null, value: null); - } + => AcceptedAtAction(actionName, controllerName, routeValues: null, value: null); /// /// Creates a object that produces an response. @@ -1765,9 +1663,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, object value) - { - return AcceptedAtAction(actionName, routeValues: null, value: value); - } + => AcceptedAtAction(actionName, routeValues: null, value: value); /// /// Creates a object that produces an response. @@ -1778,9 +1674,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, string controllerName, object routeValues) - { - return AcceptedAtAction(actionName, controllerName, routeValues, value: null); - } + => AcceptedAtAction(actionName, controllerName, routeValues, value: null); /// /// Creates a object that produces an response. @@ -1791,9 +1685,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, object routeValues, object value) - { - return AcceptedAtAction(actionName, controllerName: null, routeValues: routeValues, value: value); - } + => AcceptedAtAction(actionName, controllerName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces an response. @@ -1809,9 +1701,7 @@ namespace Microsoft.AspNetCore.Mvc string controllerName, object routeValues, object value) - { - return new AcceptedAtActionResult(actionName, controllerName, routeValues, value); - } + => new AcceptedAtActionResult(actionName, controllerName, routeValues, value); /// /// Creates a object that produces an response. @@ -1820,9 +1710,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(object routeValues) - { - return AcceptedAtRoute(routeName: null, routeValues: routeValues, value: null); - } + => AcceptedAtRoute(routeName: null, routeValues: routeValues, value: null); /// /// Creates a object that produces an response. @@ -1831,9 +1719,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(string routeName) - { - return AcceptedAtRoute(routeName, routeValues: null, value: null); - } + => AcceptedAtRoute(routeName, routeValues: null, value: null); /// /// Creates a object that produces an response. @@ -1843,9 +1729,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(string routeName, object routeValues) - { - return AcceptedAtRoute(routeName, routeValues, value: null); - } + => AcceptedAtRoute(routeName, routeValues, value: null); /// /// Creates a object that produces an response. @@ -1855,9 +1739,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(object routeValues, object value) - { - return AcceptedAtRoute(routeName: null, routeValues: routeValues, value: value); - } + => AcceptedAtRoute(routeName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces an response. @@ -1868,9 +1750,7 @@ namespace Microsoft.AspNetCore.Mvc /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(string routeName, object routeValues, object value) - { - return new AcceptedAtRouteResult(routeName, routeValues, value); - } + => new AcceptedAtRouteResult(routeName, routeValues, value); /// /// Creates a .