Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private static string MakeLocalPathPattern(string path)
 => string.Join("([^" + Regex.Escape("/?#") + "]+)", IsAttributeRx.Split(path).Select(Regex.Escape));