先看类图:
1.PathSegment和PathSubSegment两个类是基类,没有任何代码,分别代表Route规则中Url片段('/'分隔的结果)和Url片段中的子片段('{'和'}'分隔的结果)。
2.SeparatorPathSegment类代表Route规则的Url中的'/',也没有任何代码
3.ContentPathSegment类与SeparatorPathSegment类相对应
其有两个属性,Subsegments存储其所包含的PathSubsegment,IsCatchAll表示其是否包含通配的PathSubsegment
4.LiteralSubsegment类和ParameterSubsegment类,分别代表ContentPathSegment中的字符和参数
比如说一个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的最末尾。