<#@ template debug="false" hostspecific="false" language="C#" #> <#@ assembly name="System.Core" #> <#@ import namespace="System.Linq" #> <#@ import namespace="System.Text" #> <#@ import namespace="System.Collections.Generic" #> <#@ output extension=".cs" #> namespace Kit.Helpers.Routes { using System; using System.Linq.Expressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; public partial class ControllerRouteFluent : IEndPointFluent> where TController : Controller { public delegate TResult GenericResult0Delegate(); public delegate Task GenericResult0DelegateAsync(); <# string _paramsT1 = "TResult"; string _paramsD1 = string.Empty; for (int i = 1; i <= 5; i++) { string paramName = "TInput" + i.ToString(); _paramsT1 = _paramsT1 + ", " + paramName; _paramsD1 = _paramsD1 + (_paramsD1 != string.Empty ? ", " : string.Empty) + paramName + " input" + i.ToString(); #> public delegate TResult GenericResult<#= i #>Delegate<<#= _paramsT1 #>>(<#= _paramsD1 #>); public delegate Task GenericResult<#= i #>DelegateAsync<<#= _paramsT1 #>>(<#= _paramsD1 #>); <# } #> <# var actionTypes = new List> { new ("Generic", "TResult", true), new ("Json", "JsonResult", false), new ("Empty", "EmptyResult", false), new ("Content", "ContentResult", false), new ("View", "ViewResult", false), new ("PartialView", "PartialViewResult", false), new ("Action", "IActionResult", false), }; foreach (var actionType in actionTypes) { bool withResultInGeneric = actionType.Item3; var items = new List>(); items.Add(new Tuple(actionType.Item1, 0, withResultInGeneric ? "<" + actionType.Item2 + ">" : string.Empty, actionType.Item2)); string _paramsT = withResultInGeneric ? actionType.Item2 : string.Empty; string _paramsDelegate = actionType.Item2; for (int i = 1; i <= 5; i++) { string genericString = "TInput" + i.ToString(); _paramsT += (_paramsT == string.Empty ? string.Empty : ", ") + genericString; _paramsDelegate += ", " + genericString; items.Add(new Tuple(actionType.Item1, i, "<" + _paramsT + ">", _paramsDelegate)); } #> #region <#= actionType.Item2 #> Actions <# foreach (var item in items) { #> public ControllerRouteFluent <#= item.Item1 #>Action<#= item.Item3 #>(string url, ExpressionDelegate<<#= item.Item4 #>>>> actionSelector) => this.AddRouteLambda(url, actionSelector); public ControllerRouteFluent <#= item.Item1 #>ActionAsync<#= item.Item3 #>(string url, ExpressionDelegateAsync<<#= item.Item4 #>>>> actionSelector) => this.AddRouteLambda(url, actionSelector); <# } #> #endregion <# } #> } }