First look at the class diagram:
1. pathsegment and pathsubsegmentThe two classes are base classes without anyCode, Representing the URL segments (results separated by '/') in the route rule and the Child segments (results separated by '{' and '}') in the URL segment respectively ).
2. The separatorpathsegment class represents the '/' in the URL of the route rule, and there is no code
3. The contentpathsegment class corresponds to the separatorpathsegment class.
Subsegments stores pathsubsegment. iscatchall indicates whether subsegment contains the 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=>(SEGIsParametersubsegment)&&
(Parametersubsegment) SEG). iscatchall ));
}
}
Public Ilist < Pathsubsegment > Subsegments {Get;Private Set;}
}
4. literalsubsegment class and parametersubsegment class, representing the characters and parameters in contentpathsegment respectively
Internal Sealed Class Literalsubsegment: pathsubsegment
{
// Methods
Public Literalsubsegment ( String Literal)
{
This. Literal=Literal;
}
// Properties
Public String Literal {Get;Private Set;}
}
/**/ /// <Summary>
///The parameter in the routing rule to determine whether a wildcard exists.
/// </Summary>
Internal Sealed Class Parametersubsegment: pathsubsegment
{
// Methods
Public Parametersubsegment ( String Parametername)
{
If (Parametername. startswith ( " * " , Stringcomparison. ordinal ))
{< br> This . parametername = parametername. substring ( 1 );
This . iscatchall = true ;
}
Else
This . Parametername = Parametername;
}
// Properties
Public Bool Iscatchall {Get;Private Set;}
Public String Parametername {Get;Private Set;}
}
For example, the URL of a route is {controller}/the {action}/{* ID },
Both '/' andSeparatorpathsegment, "{Controller}", "The {action}", and "{* ID}" are parsed into three contentpathsegment.
The second contentpathsegment has two pathsubsegment: one is literalsubsegment, the content is "the", the other is parametersubsegment, and the parameter name is "action"
The third contentpathsegment has a wildcard parametersubsegment, and the parameter name is "ID", so it can also be configured
It is worth noting that the wildcard contentpathsegment must be at the end of the URL, and the wildcard parametersubsegment in contentpathsegment must also be at the end.
Therefore, a URL can have only one parametersubsegment parameter, which is at the end of the URL.