public Route(string actionTemplate, ApiHandler <T> handler, Route previous) : base(actionTemplate, route => ((Route <T>)route).ToBaseHandler(handler), previous) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } _attrs = IsAttributeRx .Matches(Uri.LocalPath) .OfType <Match>() .Select(m => m.Value) .ToArray(); if (_attrs.Length == 0) { throw new ArgumentException(SR.Format(SR.ApiHandlerTemplateNoParameters)); } if (!IsBindableType(out var typeName)) { throw new ArgumentException(SR.Format(SR.ApiHanderTemplateInvalid, actionTemplate, typeName)); } _localPathPattern = MakeLocalPathPattern(Uri.LocalPath); }
private static string MakeLocalPathPattern(string path) => string.Join("([^" + Regex.Escape("/?#") + "]+)", IsAttributeRx.Split(path).Select(Regex.Escape));