![]() |
VOOZH | about |
dotnet add package FSharp.Data.LiteralProviders --version 1.0.3
NuGet\Install-Package FSharp.Data.LiteralProviders -Version 1.0.3
<PackageReference Include="FSharp.Data.LiteralProviders" Version="1.0.3" />
<PackageVersion Include="FSharp.Data.LiteralProviders" Version="1.0.3" />Directory.Packages.props
<PackageReference Include="FSharp.Data.LiteralProviders" />Project file
paket add FSharp.Data.LiteralProviders --version 1.0.3
#r "nuget: FSharp.Data.LiteralProviders, 1.0.3"
#:package FSharp.Data.LiteralProviders@1.0.3
#addin nuget:?package=FSharp.Data.LiteralProviders&version=1.0.3Install as a Cake Addin
#tool nuget:?package=FSharp.Data.LiteralProviders&version=1.0.3Install as a Cake Tool
This is a collection of type providers that provide literals: compile-time constants that can be used in regular code, but also as parameters to other type providers or .NET attributes.
FSharp.Data.LiteralProviders.Env contains literals for environment variables during compile time.
open FSharp.Data.LiteralProviders
/// The compile-time value of the "OS" environment variable
let compileOS = Env.OS.Value
match compileOS with
| "Windows_NT" -> printfn "This program was compiled on Windows!"
| "Unix" -> printfn "This program was compiled on OSX or Linux!"
| _ -> printfn "I don't know the platform this program was compiled on :("
Here is a more useful example, using it as a parameter to another type provider (namely, SQLProvider):
open FSharp.Data.Sql
open FSharp.Data.LiteralProviders
type Sql = SqlProvider<Common.DatabaseProviderTypes.MSSQLSERVER,
Env.CONNECTION_STRING.Value>
Note that when called this way, Env fails to compile if the environment variable is not set.
Alternatively, the environment variable's name can be passed as a string parameter.
In this case, Env returns the empty string if the variable is not set.
open FSharp.Data.LiteralProviders
let vsVersion = Env<"VisualStudioEdition">.Value
match vsVersion with
| "" -> printfn "This program wasn't compiled with Visual Studio."
| v -> printfn "This program was built with Visual Studio %s." v
When used with a parameter, Env also provides a value IsSet : bool
Additional parameters can be passed:
DefaultValue : string will be used as the value if the environment variable isn't set, instead of the empty string.
open FSharp.Data.Sql
open FSharp.Data.LiteralProviders
let [<Literal>] connString =
Env<"CONNECTION_STRING", "Server=localhost;Integrated Security=true">.Value
type Sql = SqlProvider<Common.DatabaseProviderTypes.MSSQLSERVER, connString>
EnsureExists : bool specifies the behavior when the environment variable isn't set.
If false (the default), then Value is an empty string (or DefaultValue if provided).
If true, then the type provider raises a compile-time error.
/// Throws a compile-time error "Environment variable does not exist: CONNECTION_STRING".
let [<Literal>] connString = Env<"CONNECTION_STRING", EnsureExists = true>.Text
Tip: to pass
Envdirectly to another type provider without binding it as alet [<Literal>], use theconstoperator:type Sql = SqlProvider<Common.DatabaseProviderTypes.MSSQLSERVER, const(Env<"CONNECTION_STRING", "Server=localhost;Integrated Security=true">.Value)>
FSharp.Data.LiteralProviders.TextFile contains literals that are read from text files during compilation.
open FSharp.Data.LiteralProviders
/// The compile-time contents of the file <projectFolder>/build/version.txt
let [<Literal>] version = TextFile.build.``version.txt``.Text
Alternatively, the file path can be passed as a string parameter.
In this case, TextFile returns the empty string if the file doesn't exist.
open FSharp.Data.LiteralProviders
/// The compile-time contents of the file <projectFolder>/build/version.txt
/// or "" if this file doesn't exist.
let [<Literal>] version = TextFile<"build/version.txt">.Text
Additional parameters can be passed:
DefaultValue : string will be used as the value if the file doesn't exist, instead of the empty string.
open FSharp.Data.LiteralProviders
/// The compile-time contents of the file <projectFolder>/build/version.txt
/// or "1.0" if this file doesn't exist.
let [<Literal>] version = TextFile<"build/version.txt", DefaultValue = "1.0">.Text
Encoding : string specifies the text encoding.
The possible values are UTF-8, UTF-16-le, UTF-16-be, UTF-32-le and UTF-32-be.
When not specified, TextFile tries to guess the encoding.
open FSharp.Data.LiteralProviders
let [<Literal>] script = TextFile<"LoadData.sql", Encoding = "UTF-16-le">.Text
Note: regardless of the encoding, if the file starts with a byte order mark, then the BOM is stripped from the string.
EnsureExists : bool specifies the behavior when the file doesn't exist.
If false (the default), then the Text value is an empty string (or DefaultValue if provided).
If true, then the type provider raises a compile-time error.
/// Throws a compile-time error "File does not exist: fileThatDoesntExist.txt".
let [<Literal>] test = TextFile<"fileThatDoesntExist.txt", EnsureExists = true>.Text
FSharp.Data.LiteralProviders.Exec executes an external program during compilation and captures its output.
open FSharp.Data.LiteralProviders
let [<Literal>] currentBranch = Exec<"git", "branch --show-current">.Output
Additional parameters can be passed:
Input: string: text that is passed to the program's standard output.
Directory: string: the working directory. The default is the project directory.
EnsureSuccess: bool: if true, the provider ensures that the program exits successfully, and fails otherwise.
If false, no error is raised.
The default is true.
Timeout: int: timeout in milliseconds. Raise an error if the program takes longer to finish.
The default is 10_000 (10 seconds).
The following values are provided:
Output: string: the program's standard output.
Error: string: the program's standard error.
ExitCode: int: the program's exit code. Only useful with EnsureSuccess = false, otherwise always 0.
FSharp.Data.LiteralProviders contains sub-namespaces String, Int and Bool for conditional operations on these types.
The providers EQ and NE contain Value: bool that checks whether the two parameters are equal / not equal, respectively.
open FSharp.Data.LiteralProviders
let [<Literal>] branch = Exec<"git", "branch --show-current">.Output
let [<Literal>] isMaster = String.EQ<branch, "master">.Value
In sub-namespace Int, the providers LT, LE, GT and GE contain Value: bool that checks whether the first parameter is less than / less than or equal / greater than / greater than or equal to the second parameter, respectively.
open FSharp.Data.LiteralProviders
let [<Literal>] gitStatusCode = Exec<"git", "status", EnsureSuccess = false>.StatusCode
let [<Literal>] notInGitRepo = Int.GT<gitStatusCode, 0>.Value
In sub-namespace Bool, the providers AND, OR, XOR and NOT contain Value: bool that performs the corresponding boolean operation on its parameter(s).
open FSharp.Data.LiteralProviders
type GithubAction = Env<"GITHUB_ACTION">
let [<Literal>] isLocalBuild = Bool.NOT<GithubAction.IsSet>.Value
The provider IF takes a condition and two values as parameters.
It returns the first value if the condition is true, and the second value if the condition is false.
open FSharp.Data.LiteralProviders
let [<Literal>] versionSuffix = String.IF<isMaster, "", "-pre">.Value
FSharp.Data.LiteralProviders.BuildDate contains the build time as a literal string in ISO-8601 format ("o" format).
open FSharp.Data.LiteralProviders
let utcBuildDate = BuildDate.Utc // "2019-08-24T19:45:03.2279236Z"
let localBuildDate = BuildDate.Local // "2019-08-24T21:45:03.2279236+02:00"
It can be optionally parameterized by a date format.
open FSharp.Data.LiteralProviders
let buildTime = BuildDate<"hh:mm:ss">.Utc // "21:45:03"
The providers try to parse string values as integer and as boolean. If any of these succeed, a value suffixed with AsInt or AsBool is provided.
open FSharp.Data.LiteralProviders
let runNumber = Env<"GITHUB_RUN_NUMBER">.Value // eg. "42"
let runNumber = Env<"GITHUB_RUN_NUMBER">.ValueAsInt // eg. 42
The following values are parsed this way:
Env.ValueTextFile.TextExec.OutputExec.Error| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 is compatible. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 3 NuGet packages that depend on FSharp.Data.LiteralProviders:
| Package | Downloads |
|---|---|
|
Florence
Package Description |
|
|
Eutopia
Package Description |
|
|
Florence.Notebooks
Package Description |
Showing the top 1 popular GitHub repositories that depend on FSharp.Data.LiteralProviders:
| Repository | Stars |
|---|---|
|
Zaid-Ajaj/Npgsql.FSharp.Analyzer
F# analyzer that provides embedded SQL syntax analysis, type-checking for parameters and result sets and nullable column detection when writing queries using Npgsql.FSharp.
|