数值始终为真,即使为假。

huangapple go评论51阅读模式
英文:

Value is always true, even if false

问题

/*****For Local setup****/
var isLocal = _configuration.GetValue<bool>("IsLocalEvn");
if (isLocal)
    return isLocal;
英文:
        /*****For Local setup****/
        var isLocal = _configuration.GetValue&lt;bool&gt;(&quot;IsLocalEvn&quot;);
        if (isLocal)
            return isLocal;

This is always returning true even if the value in appsettings is false

From appsettings.json

&quot;IsLocalEvn&quot;: &quot;false&quot;,

答案1

得分: 4

你可以在JSON文件中使用boolean类型。

"IsLocalEnv": false,

在你的情况下,你使用了一个string值,当它被转换为boolean时会被解释为true

英文:

You can use the boolean type inside the JSON file.

&quot;IsLocalEvn&quot;: false,

In your case, you are using a string value which is interpreted as true when it's converted to a boolean.

huangapple
  • 本文由 发表于 2023年2月14日 22:31:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75449300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定