Thanks to visit codestin.com
Credit goes to github.com

Skip to content

System.Uri F# snippets #8055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions snippets/fsharp/System/Uri/.ctor/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="source.fs" />
<Compile Include="source1.fs" />
<Compile Include="source2.fs" />
<Compile Include="nclurienhancements.fs" />
<Compile Include="source3.fs" />
</ItemGroup>
</Project>
99 changes: 99 additions & 0 deletions snippets/fsharp/System/Uri/.ctor/nclurienhancements.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module nclurienhancements

open System

let sampleConstructor () =
//<snippet2>
// Create an absolute Uri from a string.
let absoluteUri = Uri "http://www.contoso.com/"

// Create a relative Uri from a string. allowRelative = true to allow for
// creating a relative Uri.
let relativeUri = Uri("/catalog/shownew.htm?date=today", UriKind.Relative)

// Check whether the new Uri is absolute or relative.
if not relativeUri.IsAbsoluteUri then
printfn $"{relativeUri} is a relative Uri."

// Create a new Uri from an absolute Uri and a relative Uri.
let combinedUri = Uri(absoluteUri, relativeUri)
printfn $"{combinedUri.AbsoluteUri}"
//</snippet2>

// OriginalString
let sampleOriginalString () =
//<snippet3>
// Create a new Uri from a string address.
let uriAddress = Uri "HTTP://www.ConToso.com:80//thick%20and%20thin.htm"

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version. OriginalString gives the original
// string that was passed to the constructor.

// The following outputs "http://www.contoso.com//thick and thin.htm".
printfn $"{uriAddress.ToString()}"

// The following outputs "HTTP://www.ConToso.com:80//thick%20and%20thin.htm".
printfn $"{uriAddress.OriginalString}"
//</snippet3>

// DNSSafeHost
let sampleDNSSafeHost () =
//<snippet4>
// Create new Uri using a string address.
let address = Uri "http://[fe80::200:39ff:fe36:1a2d%254]/temp/example.htm"

// Make the address DNS safe.

// The following outputs "[fe80::200:39ff:fe36:1a2d]".
printfn $"{address.Host}"

// The following outputs "fe80::200:39ff:fe36:1a2d%254".
printfn $"{address.DnsSafeHost}"
//</snippet4>

// operator = and <>
let sampleOperatorEqual () =
//<snippet5>
// Create some Uris.
let address1 = Uri "http://www.contoso.com/index.htm#search"
let address2 = Uri "http://www.contoso.com/index.htm"
let address3 = Uri "http://www.contoso.com/index.htm?date=today"

// The first two are equal because the fragment is ignored.
if address1 = address2 then
printfn $"{address1} is equal to {address2}"

// The second two are not equal.
if address2 <> address3 then
printfn $"{address2} is not equal to {address3}"
//</snippet5>

// IsBaseOf
let sampleIsBaseOf () =
//<snippet6>
// Create a base Uri.
let baseUri = Uri "http://www.contoso.com/"

// Create a new Uri from a string.
let uriAddress = Uri "http://www.contoso.com/index.htm?date=today"

// Determine whether BaseUri is a base of UriAddress.
if baseUri.IsBaseOf uriAddress then
printfn $"{baseUri} is the base of {uriAddress}"
//</snippet6>

// Constructor
sampleConstructor ()

// OriginalString
sampleOriginalString ()

// DNSSafeHost
sampleDNSSafeHost ()

// operator = and <>
sampleOperatorEqual ()

// IsBaseOf
sampleIsBaseOf ()
7 changes: 7 additions & 0 deletions snippets/fsharp/System/Uri/.ctor/source.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module source

open System

// <Snippet1>
let myUri = Uri "http://www.contoso.com/"
// </Snippet1>
7 changes: 7 additions & 0 deletions snippets/fsharp/System/Uri/.ctor/source1.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module source1

open System

// <Snippet1>
let myUri = Uri("http://www.contoso.com/Hello%20World.htm", true)
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/Uri/.ctor/source2.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module source2

open System

// <Snippet1>
let baseUri = Uri "http://www.contoso.com"
let myUri = Uri(baseUri, "catalog/shownew.htm")

printfn $"{myUri}"
// </Snippet1>
8 changes: 8 additions & 0 deletions snippets/fsharp/System/Uri/.ctor/source3.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module source3

open System

// <Snippet1>
let baseUri = Uri "http://www.contoso.com"
let myUri = Uri(baseUri, "Hello%20World.htm", false)
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/Uri/AbsolutePath/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="source.fs" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions snippets/fsharp/System/Uri/AbsolutePath/source.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// <Snippet1>
open System

let baseUri = Uri "http://www.contoso.com/"
let myUri = Uri(baseUri, "catalog/shownew.htm?date=today")

printfn $"{myUri.AbsolutePath}"
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/Uri/AbsoluteUri/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="source.fs" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions snippets/fsharp/System/Uri/AbsoluteUri/source.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// <Snippet1>
open System

let baseUri= Uri "http://www.contoso.com"
let myUri = Uri(baseUri,"catalog/shownew.htm?date=today")

printfn $"{myUri.AbsoluteUri}"
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/Uri/Authority/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="source.fs" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions snippets/fsharp/System/Uri/Authority/source.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// <Snippet1>
open System

let baseUri = Uri "http://www.contoso.com:8080/"
let myUri = Uri(baseUri, "shownew.htm?date=today")

printfn $"{myUri.Authority}"
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/Uri/CheckHostName/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="source.fs" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions snippets/fsharp/System/Uri/CheckHostName/source.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
open System

// <Snippet1>
printfn $"""{Uri.CheckHostName "www.contoso.com"}"""
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/Uri/CheckSchemeName/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="uriexamples.fs" />
</ItemGroup>
</Project>
Loading