public void VisitStatic(SillyHardCodedSegment hardCoded) { if (hardCoded.IsRoot && String.IsNullOrEmpty(currentSegment)) { segmentConsumed = true; return; } if (String.Compare(hardCoded.Value, currentSegment, true) == 0) { segmentConsumed = true; } else { matchFailed = true; } }
private void ParseUrlPattern() { if (String.IsNullOrEmpty(UrlPattern) || String.IsNullOrWhiteSpace(UrlPattern)) { SetInvalid("Url pattern is null, empty, or nothing but whitespace"); return; } if (UrlPattern[0] != '/') { SetInvalid("Url pattern must open with '/'"); return; } string[] matches = UrlPattern.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (matches == null || matches.Length == 0) { SillySegment rootSegment = new SillyHardCodedSegment(); Add(rootSegment); return; } bool controllerSet = false, methodSet = false; foreach (string match in matches) { if (String.Compare("/", match, true) == 0) { continue; } SillySegment segment = ProduceFromSegment(match); if (segment == null) { SetInvalid("Cannot find a suitable match for Url segment '" + match + "'"); return; } if (segment.Type == SegmentTypes.Controller) { if (controllerSet) { SetInvalid("Cannot define multiple :controller segments in a Url pattern"); return; } controllerSet = true; if (methodSet) { SetInvalid("Cannot define :method before :controller in a Url pattern"); return; } if (VarCount > 0) { SetInvalid("Cannot define {vars} before :controller in a Url pattern"); return; } } if (segment.Type == SegmentTypes.Method) { if (methodSet) { SetInvalid("Cannot define multiple :method segments in a Url pattern"); return; } methodSet = true; if (VarCount > 0) { SetInvalid("Cannot define {vars} before :method in a Url pattern"); return; } } Add(segment); } }