Skip to content

Instantly share code, notes, and snippets.

@jdluzen
Created February 2, 2021 01:49
Show Gist options
  • Save jdluzen/92c0ed4409a06350019bc0711acd2777 to your computer and use it in GitHub Desktop.
Save jdluzen/92c0ed4409a06350019bc0711acd2777 to your computer and use it in GitHub Desktop.
Parse the route attribute names out of route templates e.g. /main/view/{id}
private static IEnumerable<string> GetRouteParameters(RouteAttribute route)
{
for (int i = 0; i < route.Template.Length; i++)
{
if (route.Template[i] != '{')
continue;
i++;
for (int j = i; j < route.Template.Length; j++)
{
if (route.Template[j] != '}')
continue;
else
{
yield return route.Template[i..j];
i = j;
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment