Skip to content

Commit 8f58082

Browse files
authored
Version F# snippetrs (dotnet#8076)
1 parent d377a71 commit 8f58082

File tree

15 files changed

+284
-0
lines changed

15 files changed

+284
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="rev.fs" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//<snippet1>
2+
// This example demonstrates the Version.Revision,
3+
// MajorRevision, and MinorRevision properties.
4+
open System
5+
6+
let std = Version(2, 4, 1128, 2)
7+
let interim = Version(2, 4, 1128, (100 <<< 16) + 2)
8+
9+
printfn $"Standard version:\n major.minor.build.revision = {std.Major}.{std.Minor}.{std.Build}.{std.Revision}"
10+
printfn $"Interim version:\n major.minor.build.majRev/minRev = {interim.Major}.{interim.Minor}.{interim.Build}.{interim.MajorRevision}/{interim.MinorRevision}"
11+
12+
// This code example produces the following results:
13+
// Standard version:
14+
// major.minor.build.revision = 2.4.1128.2
15+
// Interim version:
16+
// major.minor.build.majRev/minRev = 2.4.1128.100/2
17+
//</snippet1>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module GettingVersions1
2+
3+
open System
4+
5+
let getOsVersion () =
6+
// <Snippet1>
7+
// Get the operating system version.
8+
let os = Environment.OSVersion
9+
let ver = os.Version
10+
printfn $"Operating System: {os.VersionString} ({ver})"
11+
// </Snippet1>
12+
13+
let getClrVersion () =
14+
// <Snippet2>
15+
// Get the common language runtime version.
16+
let ver = Environment.Version
17+
printfn $"CLR Version {ver}"
18+
// </Snippet2>
19+
20+
getOsVersion ()
21+
printfn ""
22+
getClrVersion ()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module comparisons1
2+
3+
// <Snippet1>
4+
open System
5+
6+
let v1 = Version(2, 0)
7+
let v2 = Version "2.1"
8+
9+
printf $"Version {v1} is "
10+
11+
match v1.CompareTo v2 with
12+
| 0 -> printf "the same as"
13+
| 1 -> printf "later than"
14+
| _ -> printf "earlier than"
15+
16+
printf $" Version {v2}."
17+
// The example displays the following output:
18+
// Version 2.0 is earlier than Version 2.1.
19+
// </Snippet1>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module comparisons2
2+
3+
// <Snippet2>
4+
open System
5+
6+
type VersionTime =
7+
| Earlier = -1
8+
| Same = 0
9+
| Later = 1
10+
11+
let showRelationship (v1: Version) (v2: Version) =
12+
printfn $"Relationship of {v1} to {v2}: {v1.CompareTo v2 |> enum<VersionTime>}"
13+
14+
let v1 = Version(1, 1)
15+
let v1a = Version "1.1.0"
16+
showRelationship v1 v1a
17+
18+
let v1b = Version(1, 1, 0, 0)
19+
showRelationship v1b v1a
20+
21+
// The example displays the following output:
22+
// Relationship of 1.1 to 1.1.0: Earlier
23+
// Relationship of 1.1.0.0 to 1.1.0: Later
24+
// </Snippet2>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module currentapp
2+
3+
// <Snippet5>
4+
open System.Reflection
5+
6+
// Get the version of the executing assembly (that is, this assembly).
7+
let assem = Assembly.GetEntryAssembly()
8+
let assemName = assem.GetName()
9+
let ver = assemName.Version
10+
printfn $"Application {assemName.Name}, Version {ver}"
11+
// </Snippet5>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module currentassem
2+
3+
// <Snippet4>
4+
type Example = class end
5+
6+
// Get the version of the current assembly.
7+
let assem = typeof<Example>.Assembly
8+
let assemName = assem.GetName()
9+
let ver = assemName.Version
10+
printfn $"{assemName.Name}, Version {ver}"
11+
// </Snippet4>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module example1
2+
3+
// <Snippet6>
4+
open System.Reflection
5+
6+
[<assembly: AssemblyVersionAttribute "2.0.1">]
7+
do ()
8+
9+
type Example1 = class end
10+
11+
let thisAssem = typeof<Example1>.Assembly
12+
let thisAssemName = thisAssem.GetName()
13+
14+
let ver = thisAssemName.Version
15+
16+
printfn $"This is version {ver} of {thisAssemName.Name}."
17+
// The example displays the following output:
18+
// This is version 2.0.1.0 of Example1.
19+
// </Snippet6>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net48</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="GettingVersions1.fs" />
9+
<Compile Include="currentapp.fs" />
10+
<Compile Include="currentassem.fs" />
11+
<Compile Include="specificassem.fs" />
12+
<Compile Include="comparisons1.fs" />
13+
<Compile Include="comparisons2.fs" />
14+
<Compile Include="example1.fs" />
15+
</ItemGroup>
16+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module specificassem
2+
3+
// <Snippet3>
4+
open System.Reflection
5+
6+
// Get the version of a specific assembly.
7+
let filename = @".\StringLibrary.dll"
8+
let assem = Assembly.ReflectionOnlyLoadFrom filename
9+
let assemName = assem.GetName()
10+
let ver = assemName.Version
11+
printfn $"{assemName.Name}, Version {ver}"
12+
// </Snippet3>

0 commit comments

Comments
 (0)