Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @moxy
- @attribute required string RouteTemplate
- @moxy
- {{
- $routeParameterTypesAndNames = [];
- $urlSegmentsForRouteAttribute = [];
- $getRouteMethodFormatParts = [];
- $getRouteMethodParameterSources = [];
- $segments = RouteTemplate | regex.split("/");
- for $segment in $segments
- $match = $segment | regex.match `\{(\w+)\s*:?(\w+)\}?`;
- if !$match[0]
- $urlSegmentsForRouteAttribute = $urlSegmentsForRouteAttribute | array.add($segment)
- $getRouteMethodFormatParts = $getRouteMethodFormatParts | array.add($segment)
- else
- $paramName = $match[1]
- $paramType = $match[2]
- $getRouteMethodFormatParts = $getRouteMethodFormatParts | array.add("{" + $paramName + "}")
- $getRouteMethodParameterSources = $getRouteMethodParameterSources | array.add($paramType + " " + $paramName);
- $routeParameterTypesAndNames = $routeParameterTypesAndNames | array.add({ Name: $paramName, Type: $paramType})
- if $match[2] != "string"
- $urlSegmentsForRouteAttribute = $urlSegmentsForRouteAttribute | array.add($segment)
- else
- $urlSegmentsForRouteAttribute = $urlSegmentsForRouteAttribute | array.add('{' + $match[1] + '}')
- end
- end
- end
- capture $parametersSource
- for $currentParameter in $routeParameterTypesAndNames
- "[Parameter] public " + $currentParameter.Type + " " + $currentParameter.Name + " { get; set; }\r\n"
- end
- end
- $routeAttributeString = $urlSegmentsForRouteAttribute | array.join("/");
- $getRouteSignatureSource = $getRouteMethodParameterSources | array.join(", ")
- $getRouteFormat = $getRouteMethodFormatParts | array.join("/")
- }}
- namespace {{ moxy.Class.Namespace }}
- {
- using Microsoft.AspNetCore.Components;
- [Route("{{ $routeAttributeString }}")]
- partial class {{ moxy.Class.Name }}
- {
- public static string GetPageUrl({{ $getRouteSignatureSource }}) => $"{{$getRouteFormat}}";
- {{ $parametersSource }}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement