假设我有一个ConfigurationProperty是这样定义的:
[ConfigurationProperty("TheProp")]
public double TheProp
{
get{//some code}
set{//some code}
}如何检查这个ConfigurationProperty是否有一个值?在这种情况下,DefaultValue将无法工作,因为任何双值都是配置属性的有效值。
发布于 2014-09-01 09:23:42
您可以尝试使属性‘Nullable’的type:
[ConfigurationProperty("TheProp")]
public double? TheProp
{
get{//some code}
set{//some code}
}这将允许您测试if(TheProp.HasValue)。
发布于 2020-10-20 09:40:06
ElementInformation有一个属性"IsModified“,您可以使用该属性来确定是否为配置属性分配了如下值:
ConfigurationElement instance = //your configuration property
if (instance.ElementInformation.Properties["propertyname"].IsModified)
{
//property has been assigned a value
}或者你可以循环通过PropertyInformationCollection。
https://stackoverflow.com/questions/25602309
复制相似问题