TimeSpanValidatorAttribute
Declaratively instructs the .NET Framework to perform time validation on a configuration property. This class cannot be inherited.
using System.Globalization;
namespace System.Configuration
{
[AttributeUsage(AttributeTargets.Property)]
public sealed class TimeSpanValidatorAttribute : ConfigurationValidatorAttribute
{
public const string TimeSpanMinValue = "-10675199.02:48:05.4775808";
public const string TimeSpanMaxValue = "10675199.02:48:05.4775807";
public override ConfigurationValidatorBase ValidatorInstance => new TimeSpanValidator(MinValue, MaxValue, ExcludeRange);
public TimeSpan MinValue { get; set; } = TimeSpan.MinValue;
public TimeSpan MaxValue { get; set; } = TimeSpan.MaxValue;
public string MinValueString {
get {
return MinValue.ToString();
}
set {
TimeSpan timeSpan = TimeSpan.Parse(value, CultureInfo.InvariantCulture);
if (MaxValue < timeSpan)
throw new ArgumentOutOfRangeException("value", System.SR.Validator_min_greater_than_max);
MinValue = timeSpan;
}
}
public string MaxValueString {
get {
return MaxValue.ToString();
}
set {
TimeSpan timeSpan = TimeSpan.Parse(value, CultureInfo.InvariantCulture);
if (MinValue > timeSpan)
throw new ArgumentOutOfRangeException("value", System.SR.Validator_min_greater_than_max);
MaxValue = timeSpan;
}
}
public bool ExcludeRange { get; set; }
}
}