1
+ module nclurienhancements
2
+
3
+ open System
4
+
5
+ let sampleConstructor () =
6
+ //<snippet2>
7
+ // Create an absolute Uri from a string.
8
+ let absoluteUri = Uri " http://www.contoso.com/"
9
+
10
+ // Create a relative Uri from a string. allowRelative = true to allow for
11
+ // creating a relative Uri.
12
+ let relativeUri = Uri( " /catalog/shownew.htm?date=today" , UriKind.Relative)
13
+
14
+ // Check whether the new Uri is absolute or relative.
15
+ if not relativeUri.IsAbsoluteUri then
16
+ printfn $" {relativeUri} is a relative Uri."
17
+
18
+ // Create a new Uri from an absolute Uri and a relative Uri.
19
+ let combinedUri = Uri( absoluteUri, relativeUri)
20
+ printfn $" {combinedUri.AbsoluteUri}"
21
+ //</snippet2>
22
+
23
+ // OriginalString
24
+ let sampleOriginalString () =
25
+ //<snippet3>
26
+ // Create a new Uri from a string address.
27
+ let uriAddress = Uri " HTTP://www.ConToso.com:80//thick%20a nd%20t hin.htm"
28
+
29
+ // Write the new Uri to the console and note the difference in the two values.
30
+ // ToString() gives the canonical version. OriginalString gives the original
31
+ // string that was passed to the constructor.
32
+
33
+ // The following outputs "http://www.contoso.com//thick and thin.htm".
34
+ printfn $" {uriAddress.ToString()}"
35
+
36
+ // The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
37
+ printfn $" {uriAddress.OriginalString}"
38
+ //</snippet3>
39
+
40
+ // DNSSafeHost
41
+ let sampleDNSSafeHost () =
42
+ //<snippet4>
43
+ // Create new Uri using a string address.
44
+ let address = Uri " http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm"
45
+
46
+ // Make the address DNS safe.
47
+
48
+ // The following outputs "[fe80::200:39ff:fe36:1a2d]".
49
+ printfn $" {address.Host}"
50
+
51
+ // The following outputs "fe80::200:39ff:fe36:1a2d%254".
52
+ printfn $" {address.DnsSafeHost}"
53
+ //</snippet4>
54
+
55
+ // operator = and <>
56
+ let sampleOperatorEqual () =
57
+ //<snippet5>
58
+ // Create some Uris.
59
+ let address1 = Uri " http://www.contoso.com/index.htm#search"
60
+ let address2 = Uri " http://www.contoso.com/index.htm"
61
+ let address3 = Uri " http://www.contoso.com/index.htm?date=today"
62
+
63
+ // The first two are equal because the fragment is ignored.
64
+ if address1 = address2 then
65
+ printfn $" {address1} is equal to {address2}"
66
+
67
+ // The second two are not equal.
68
+ if address2 <> address3 then
69
+ printfn $" {address2} is not equal to {address3}"
70
+ //</snippet5>
71
+
72
+ // IsBaseOf
73
+ let sampleIsBaseOf () =
74
+ //<snippet6>
75
+ // Create a base Uri.
76
+ let baseUri = Uri " http://www.contoso.com/"
77
+
78
+ // Create a new Uri from a string.
79
+ let uriAddress = Uri " http://www.contoso.com/index.htm?date=today"
80
+
81
+ // Determine whether BaseUri is a base of UriAddress.
82
+ if baseUri.IsBaseOf uriAddress then
83
+ printfn $" {baseUri} is the base of {uriAddress}"
84
+ //</snippet6>
85
+
86
+ // Constructor
87
+ sampleConstructor ()
88
+
89
+ // OriginalString
90
+ sampleOriginalString ()
91
+
92
+ // DNSSafeHost
93
+ sampleDNSSafeHost ()
94
+
95
+ // operator = and <>
96
+ sampleOperatorEqual ()
97
+
98
+ // IsBaseOf
99
+ sampleIsBaseOf ()
0 commit comments