F#: Extract key value pairs from an app config file

The following snippet extracts key value pairs from the AppSettings section of an app config file:

        let appSettings = ConfigurationManager.AppSettings
        let serviceKeys = ConfigurationManager.AppSettings.AllKeys 
                           |> Seq.filter (fun k -> k.ToString().EndsWith "Fn") 
                           |> Seq.map    (fun k -> (k,appSettings.GetValues(k).First()))
  <appSettings>
    <add key="MyAzureFn"       value="some_value_1"/>
    <add key="MyOtherAzureFn"  value="some_value_2"/>
    <add key="MyThirdAzureFn"  value="some_value_3"/>
  </appSettings>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: