The AppSettings type provider
This tutorial shows the use of the AppSettings type provider. It allows to access app.config files in a strongly typed way.
Using App.Settings from F# scripts
Create a config file called app.config
like this:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
|
Reference the type provider assembly and configure it to use your app.settings file:
1: 2: 3: 4: 5: |
|
Now you have typed access to your app.config files:
Reading and writing from the config
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: |
|
Using AppSettingsProvider in *.fsx-script
The default executable is the current project .config. (Which is Fsi.exe.config in F# interactive.) How ever, if you want to modify the configuration of some other application, you can do with SelectExecutableFile-method:
1: 2: 3: |
|
Multiple items
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp.Configuration
type Settings = AppSettings<...>
Full name: AppSettingsProvider.Settings
Full name: AppSettingsProvider.Settings
type AppSettings
Full name: FSharp.Configuration.AppSettings
Full name: FSharp.Configuration.AppSettings
property AppSettings<...>.Test2: string
Returns the value from app.config with key test2
Returns the value from app.config with key test2
property AppSettings<...>.ConfigFileName: string
Returns the Filename
Returns the Filename
type ConnectionStrings =
static member LocalSqlServer : string with get, set
static member LocalSqliteServer : string with get, set
static member Test : string with get, set
Full name: FSharp.Configuration.AppSettings,configFileName="app.config".ConnectionStrings
Represents the available connection strings from app.config
static member LocalSqlServer : string with get, set
static member LocalSqliteServer : string with get, set
static member Test : string with get, set
Full name: FSharp.Configuration.AppSettings,configFileName="app.config".ConnectionStrings
Represents the available connection strings from app.config
property AppSettings<...>.ConnectionStrings.Test: string
Returns the connection string from app.config with name Test
Returns the connection string from app.config with name Test
val path : string
Full name: AppSettingsProvider.path
Full name: AppSettingsProvider.path
namespace System
namespace System.IO
type Path =
static val InvalidPathChars : char[]
static val AltDirectorySeparatorChar : char
static val DirectorySeparatorChar : char
static val PathSeparator : char
static val VolumeSeparatorChar : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
static val InvalidPathChars : char[]
static val AltDirectorySeparatorChar : char
static val DirectorySeparatorChar : char
static val PathSeparator : char
static val VolumeSeparatorChar : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
System.IO.Path.Combine([<System.ParamArray>] paths: string []) : string
System.IO.Path.Combine(path1: string, path2: string) : string
System.IO.Path.Combine(path1: string, path2: string, path3: string) : string
System.IO.Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
System.IO.Path.Combine(path1: string, path2: string) : string
System.IO.Path.Combine(path1: string, path2: string, path3: string) : string
System.IO.Path.Combine(path1: string, path2: string, path3: string, path4: string) : string
AppSettings<...>.SelectExecutableFile(pathOfExe: string) : Unit
Property to change the executable file that is read for configurations. This idea is that you can manage other executables also (e.g. from script).
Property to change the executable file that is read for configurations. This idea is that you can manage other executables also (e.g. from script).