System. Web. Routing namespace code parsing (4) entity classes used in route parsing, some classes named after "segment"

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.