gpt4 book ai didi

F# 尝试访问 ConfigurationManager

转载 作者:行者123 更新时间:2023-12-01 13:36:44 27 4
gpt4 key购买 nike

<分区>

我正在构建一个小项目以更好地理解 F#。作为其中的一部分,我想要一个函数“myAppSettings”,它使用 System.Configuration.ConfigurationManager 从 AppSettings.config 文件中读取设置。我把它放在我的解决方案中一个名为 myAppSettings 的单独文件中,它看起来像这样:

namespace foo.bar
open System
open System.Configuration

module myAppSettings =
let read key mandatory =
let appSettings = ConfigurationManager.AppSettings
let value = appSettings key
if mandatory && String.IsNullOrEmpty(value) then
failwith "bad hombres"
value

然而,这并没有编译,我得到了错误:

Error 1 The namespace or module 'ConfigurationManager' is not defined

我知道那个对象在 System.Configuration 中(一直在 C# 中使用它)所以我一定是在某个地方有语法错误,但是在哪里呢?

我也试过:

let appSettings = new ConfigurationManager.AppSettings
let value = appSettings key

然后找到 ConfigurationManager(new 关键字有帮助)但随后反对“let value”:

Error 1 Incomplete structured construct at or before this point in expression

我想了解这两条错误消息以及访问 app.config 文件中设置的正确方法。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com