.Net - 将Settings.settings文件中的设置设置为null [英] .Net - Set a Setting in Settings.settings file to null
问题描述
问题
可以将在设置文件(Settings.settings)中创建的设置的值覆盖为
$ b b
我有一个项目( SO.Example
),它有一个Settings.setting文件定义一个设置 SetMeToNull
:
<我有另一个项目( SO.Example.Web
)使用 SO.Example code>。我想在
So.Exmaple.Web
的web.config中将 SetMeToNull
设置为null:
< SO.Example.Properties.Settings>
< setting name =SetMeToNullserializeAs =String>
< value> [[NULL]]< / value>
< / setting>
< /SO.Example.Properties.Settings>
显然,如果不可能,有办法解决这个问题,但如果可能。
调整
一个空字符串可以舒适地坐在一个空字符串。然而,目前,我面临着一个空字符串与空字符串没有相同含义的情况。为了讨论,让我们说 SO.Example
是一个第三方库,我不能控制它。
您可以使用XML编辑器打开设置文件,而不是默认编辑器并将其手动设置为:
<设置名称=设置Type =System.String User>
< Value Profile =(默认)>< / Value>
< / Setting>
但是我想知道设置为null的设置是否有意义。
Question
Is it possible to override the value of a settings created in a settings file (Settings.settings) to be null in a app.config or web.config?
Scenario
I have a project (SO.Example
) that has a Settings.setting file that defines a setting SetMeToNull
:
I have another project (SO.Example.Web
) that uses SO.Example
. I would like to set SetMeToNull
to null in the So.Exmaple.Web
's web.config:
<SO.Example.Properties.Settings>
<setting name="SetMeToNull" serializeAs="String">
<value>[[NULL]]</value>
</setting>
</SO.Example.Properties.Settings>
Obviously there are ways to work around this if it's not possible, but it would be convenient if it was possible.
Justification
This may seam like an odd requirement when in most cases an empty string could comfortably sit in for a null string. At the moment, however, I'm faced with a case where a null string does not have the same meaning as an empty string. For the sake of the argument, let's just say SO.Example
is a 3rd party library and I have no control over it. (Ie refactoring it would take more time than it's worth).
You can open the settings file with the XML editor instead of the default editor and set it manually to:
<Setting Name="Setting" Type="System.String" Scope="User">
<Value Profile="(Default)"></Value>
</Setting>
But I wonder if it makes any sense to have a setting set to null..
这篇关于.Net - 将Settings.settings文件中的设置设置为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!