2010-06-30 82 views
14

看來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"]; 
    } 
} 

與配置看起來像這樣:

<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" /> 

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

回答

22

使用日期和時間之間的.分離器:

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

TimeSpan format的定義爲:

... [ - ] d.hh:MM:SS.FF ,其中可選的負號表示負的時間間隔,d分量是天,hh是24小時制測量的小時,mm是分鐘,ss是秒,ff是秒的分數。

+2

我的眼睛一定已經釉過了 – BozoJoe 2010-06-30 00:27:02