TimeSpan的ConfigurationElement似乎不能处理大于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
发布于 2010-06-30 08:21:11
在天和小时之间使用.分隔符:
<SequenceRolloverPolling
SequenceRolloverDOSCompare="2.00:00:00" />TimeSpan format定义为:
... -d.hh:mm:ss.ff,其中可选的减号表示负的时间间隔,d部分是天,hh是按24小时制测量的小时,mm是分钟,ss是秒,ff是秒的分数。
https://stackoverflow.com/questions/3145691
复制相似问题