惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
The Blog of Author Tim Ferriss
V
Visual Studio Blog
GbyAI
GbyAI
B
Blog RSS Feed
H
Help Net Security
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Cloudflare Blog
Security Latest
Security Latest
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
P
Privacy & Cybersecurity Law Blog
J
Java Code Geeks
博客园 - 【当耐特】
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Threatpost
Schneier on Security
Schneier on Security
T
Tenable Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Latest news
Latest news
P
Proofpoint News Feed
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
W
WeLiveSecurity
G
GRAHAM CLULEY
P
Palo Alto Networks Blog
The Hacker News
The Hacker News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
Recent Commits to openclaw:main
Recent Commits to openclaw:main
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
博客园_首页
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threat Research - Cisco Blogs
T
Tor Project blog
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
月光博客
月光博客

博客园 - Andrew Yin

数据访问层组件设计以及选型意识流 第四次扩展的讨论 数据访问层组件设计以及选型意识流 第三次封装(极致、极简而不简单) 数据访问层组件设计以及选型意识流 第二次封装以及各种牢骚 数据访问层组件设计以及选型意识流 第一次封装 数据访问层组件设计以及选型意识流 开篇 UTF-8, Unicode, GB2312三种编码方式解析, 深入研究汉字编码 C++中的模板实例:链表模板 一步一步学Ruby系列(二):Ruby中的函数 一步一步学Ruby系列(一):Ruby基础知识 .NET下的AOP: PostSharp 原理分析 AST,DLR,Expression Tree-----------推荐一位牛人的博客! C# 交互式SHELL C#中的 eval System.Web.Routing命名空间代码解析(三) RouteCollection类 System.Web.Routing命名空间代码解析(二) Routing类(上) System.Web.Routing命名空间代码解析(一) RouteBase类,RouteData类,RouteValueDictionary类 ASP.NET MVC中的各种上下文对象 有关string和Cookie的几个有用的扩展方法 反射加异步,根据枚举值来异步执行方法 操作Enum的一些实用方法
System.Web.Routing命名空间代码解析(四) Route解析中用到的实体类,一些以"Segment”为名的类
Andrew Yin · 2008-12-05 · via 博客园 - Andrew Yin

先看类图:

1.PathSegment和PathSubSegment两个类是基类,没有任何代码,分别代表Route规则中Url片段('/'分隔的结果)和Url片段中的子片段('{'和'}'分隔的结果)。

2.SeparatorPathSegment类代表Route规则的Url中的'/',也没有任何代码

3.ContentPathSegment类与SeparatorPathSegment类相对应

其有两个属性,Subsegments存储其所包含的PathSubsegment,IsCatchAll表示其是否包含通配的PathSubsegment

    internal sealed class ContentPathSegment : PathSegment
    
{
        
// Methods
        public ContentPathSegment(IList<PathSubsegment> subsegments)
        
{
            
this.Subsegments = subsegments;
        }


        
// Properties
        public bool IsCatchAll
        
{
            
get
            
{
                
return
                    
this.Subsegments.Any(seg => ((seg is ParameterSubsegment) && ((ParameterSubsegment) seg).IsCatchAll));
            }

        }


        
public IList<PathSubsegment> Subsegments getprivate set; }
    }

4.LiteralSubsegment类和ParameterSubsegment类,分别代表ContentPathSegment中的字符和参数

    internal sealed class LiteralSubsegment : PathSubsegment
    
{
        
// Methods
        public LiteralSubsegment(string literal)
        
{
            
this.Literal = literal;
        }


        
// Properties
        public string Literal getprivate set; }
    }


    
/// <summary>
    
/// Routing Rule中的参数,判断是否有通配符
    
/// </summary>

    internal sealed class ParameterSubsegment : PathSubsegment
    
{
        
// Methods
        public ParameterSubsegment(string parameterName)
        
{
            
if (parameterName.StartsWith("*", StringComparison.Ordinal))
            
{
                
this.ParameterName = parameterName.Substring(1);
                
this.IsCatchAll = true;
            }

            
else
                
this.ParameterName = parameterName;
        }


        
// Properties
        public bool IsCatchAll getprivate set; }

        
public string ParameterName getprivate set; }
    }

比如说一个Route的Url是{controller}/the{action}/{*id},

其中的'/'都是SeparatorPathSegment,"{controller}"、"the{action}"和"{*id}”被解析为三个ContentPathSegment.

其中第二个ContentPathSegment有两个PathSubsegment:一个是LiteralSubsegment,内容为"the",另一个是ParameterSubsegment,  参数名为"action"

第三个ContentPathSegment有一个通配ParameterSubsegment,  参数名为"id",所以它自己也能通配

值得注意的是通配ContentPathSegment必须位于Url的末尾,ContentPathSegment中的通配ParameterSubsegment也必须位于末尾

所以一个Url中只能有一个通配ParameterSubsegment,并且位于Url的最末尾。