Parsing Standard Uris

The System.Uri class has built-in parsing rules for a variety of schemes, including http, https, file, ftp, gopher, mailto, news, nntp, telnet, and ldap. There are also parsers for the WCF net.tcp and net.pipe schemes. These parsing rules allow a uri using the scheme to be recognized, broken into its component parts, and validated for correctness.

Rather than writing a custom parser for each scheme, System.Uri defines a collection of flags with standard meanings that describe the syntax of the scheme. There's no documentation for this internal flag system but the names come from the standard description of URI components.

If you're curious, here are the flag sets for the net.tcp and net.pipe schemes. Next time I'll talk about a slightly more concrete set of rules for these schemes that might also aid in understanding the flags.

net.tcp

AllowIriParsing

AllowIdn

UnEscapeDotsAndSlashes

CanonicalizeAsFilePath

CompressPath

ConvertPathSlashes

PathIsRooted

AllowAnInternetHost

MayHaveFragment

MayHaveQuery

MayHavePath

MayHavePort

MustHaveAuthority

net.pipe

AllowIriParsing

AllowIdn

UnEscapeDotsAndSlashes

CanonicalizeAsFilePath

CompressPath

ConvertPathSlashes

PathIsRooted

AllowAnInternetHost

MayHaveFragment

MayHaveQuery

MayHavePath

MustHaveAuthority

If you're having trouble spotting the difference, it's just that named pipes don't allow a port specification while TCP does. This also requires net.tcp to have a default port to use, which is 808.