Пример #1
0
        public ParametricUriSegment(string expression)
        {
            if (string.IsNullOrEmpty(expression))
                throw new ArgumentNullException("expression");

            if (expression.Contains('/'))
                throw new ArgumentException("Uri segment expression cannot contains '/' characters.");

            _paramExpression = ParseExpression(expression);

            _segmentRegEx = CreateRegex(_paramExpression);
        }
Пример #2
0
        static ParametricUriSegmentExpression ParseExpression(string expression)
        {
            var paramExpression = new ParametricUriSegmentExpression() { Expression = expression };

            var match = PARAMETER_NAME_REGEX.Match(expression);
            if (!match.Success)
            {
                paramExpression.IsParametric = false;
                paramExpression.ParameterName = null;
                paramExpression.Prefix = null;
                paramExpression.Suffix = null;
                paramExpression.CatchAll = false;
            }
            else
            {
                paramExpression.IsParametric = true;
                paramExpression.ParameterName = match.Groups["name"].Value;
                paramExpression.Prefix = match.Groups["prefix"].Value;
                paramExpression.Suffix = match.Groups["suffix"].Value;
                paramExpression.CatchAll = match.Groups["catchAll"].Success;
            }

            return paramExpression;
        }
Пример #3
0
        static Regex CreateParametricRegex(ParametricUriSegmentExpression paramExpression)
        {
            string valuePattern;
            if (paramExpression.CatchAll)
                valuePattern = VALUE_CATCH_ALL;
            else
                valuePattern = VALUE_CATCH_SEGMENT;

            return CreateBaseRegex(paramExpression.Prefix, valuePattern, paramExpression.Suffix, paramExpression.CatchAll);
        }
Пример #4
0
 static Regex CreateRegex(ParametricUriSegmentExpression paramExpression)
 {
     if (paramExpression.IsParametric)
         return CreateParametricRegex(paramExpression);
     else
         return CreateFixedRegex(paramExpression);
 }
Пример #5
0
        static Regex CreateFixedRegex(ParametricUriSegmentExpression paramExpression)
        {
            string valuePattern = Regex.Escape(paramExpression.Expression);

            return CreateBaseRegex(paramExpression.Prefix, valuePattern, paramExpression.Suffix, paramExpression.CatchAll);
        }