@@ -40,17 +40,20 @@ let internal typedAppSettings (ownerType:TypeProviderForNamespaces) (cfg:TypePro
4040 let appSettings = ConfigurationManager.OpenMappedExeConfiguration( fileMap, ConfigurationUserLevel.None) .AppSettings.Settings
4141
4242 for key in appSettings.AllKeys do
43- let field =
43+ let name = niceName key
44+ let getValue = <@@ ConfigurationManager.AppSettings.[ key] @@>
45+ let prop =
4446 match ( appSettings.Item key) .Value with
45- | Int fieldValue -> ProvidedLiteralField ( niceName key , typeof< int>, fieldValue )
46- | Bool fieldValue -> ProvidedLiteralField ( niceName key , typeof< bool>, fieldValue )
47- | Double fieldValue -> ProvidedLiteralField ( niceName key , typeof< float>, fieldValue )
48- | fieldValue -> ProvidedLiteralField ( niceName key , typeof< string>, fieldValue )
47+ | Int _ -> ProvidedProperty ( name , typeof< int>, GetterCode = ( fun _ -> <@@ Int32.Parse (%% getValue ) @@>) )
48+ | Bool _ -> ProvidedProperty ( name , typeof< bool>, GetterCode = ( fun _ -> <@@ Boolean.Parse (%% getValue ) @@>) )
49+ | Double _ -> ProvidedProperty ( name , typeof< float>, GetterCode = ( fun _ -> <@@ Double.Parse (%% getValue , Globalization.NumberStyles.Any , Globalization.CultureInfo.InvariantCulture ) @@>) )
50+ | _ -> ProvidedProperty ( name , typeof< string>, GetterCode = ( fun _ -> getValue ) )
4951
50- field.AddXmlDoc ( sprintf " Returns the value from %s with key %s " configFileName key)
51- field.AddDefinitionLocation( 1 , 1 , configFileName)
52+ prop.IsStatic <- true
53+ prop.AddXmlDoc ( sprintf " Returns the value from %s with key %s " configFileName key)
54+ prop.AddDefinitionLocation( 1 , 1 , configFileName)
5255
53- typeDef.AddMember field
56+ typeDef.AddMember prop
5457
5558 typeDef
5659 with
0 commit comments