TimeSpan配置天数?

Boz*_*Joe 17 c# timespan configurationsection

看来,ConfigurationElementTimeSpan无法处理超过23:59:59较大的值.有没有解决方法?是继承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"];
    }
}
Run Code Online (Sandbox Code Playgroud)

配置看起来像这样:

<SequenceRolloverPolling SequenceRolloverDOSCompare="2:00:00:00"  />
Run Code Online (Sandbox Code Playgroud)

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"  />
Run Code Online (Sandbox Code Playgroud)

OverflowException : The TimeSpan could not be parsed because at least one of the hours, minutes, or seconds components is outside its valid range

Rex*_*x M 26

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

<SequenceRolloverPolling
    SequenceRolloverDOSCompare="2.00:00:00" />
Run Code Online (Sandbox Code Playgroud)

时间跨度格式定义为:

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

  • 我的眼睛必须釉面 (2认同)