TimeSpan配置天数?

时间:2010-06-30 00:16:30

标签: c# timespan configurationsection

ConfigurationElement的{​​{1}}似乎无法处理大于23:59:59的值。有没有解决方法?是继承TimeSpan,并使新的TimeSpan成功吗?我需要处理从几分钟到几天的时间跨度。

我正在使用以下配置部分

TimeSpanValidatorAttribute

配置如下:

[ConfigurationProperty("SequenceRolloverDOSCompare", IsRequired = true)]
[TimeSpanValidator(MinValueString = "0:0:00", MaxValueString = 10675199.02:48:05.4775807", ExcludeRange = false)]
public TimeSpan SequenceRolloverDOSCompare
{
    get
    {
        return (TimeSpan)base["SequenceRolloverDOSCompare"];
    }
}

给出<SequenceRolloverPolling SequenceRolloverDOSCompare="2:00:00:00" />

或者这个:

ConfigurationErrorsException : The value of the property 'SequenceRolloverDOSCompare' cannot be parsed. The error is: 2:00:00:00 is not a valid value for TimeSpan.

给出<SequenceRolloverPolling SequenceRolloverDOSCompare="48:00:00" />

1 个答案:

答案 0 :(得分:26)

在天和小时之间使用.分隔符:

<SequenceRolloverPolling
    SequenceRolloverDOSCompare="2.00:00:00" />

TimeSpan format定义为:

  

... [ - ] d.hh:mm:ss.ff,其中可选的减号表示负时间间隔,d分量是天,hh是24小时制测量的小时数,mm是分钟,ss是秒,ff是几分之一秒。