/// <summary> /// 构造方法 /// </summary> /// <param name="url">必须是“占位符”风格的URL</param> public RouteAttribute(string url) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException(nameof(url)); } this.Url = url; this.Regex = RouteHelper.CreateRegex(this.Url); // 必须是“占位符”风格的URL }
/// <summary> /// 构造方法 /// </summary> /// <param name="url"></param> /// <param name="type"></param> public RouteUrlAttribute(string url, UrlType type) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException(nameof(url)); } this.Url = url; this.UrlType = type; if (type == UrlType.Pattern) { this.Regex = RouteHelper.CreateRegex(this.Url); } else if (type == UrlType.Regex) { this.Regex = new Regex(this.Url, RegexOptions.Compiled | RegexOptions.IgnoreCase); } }
public override bool IsMatch(HttpContext context) { return(RouteHelper.IsMatchRequest(context, Attr.Regex)); }