TimeSpanSecondsConverter
Converts a time span expressed in seconds.
using System.ComponentModel;
using System.Globalization;
namespace System.Configuration
{
public class TimeSpanSecondsConverter : ConfigurationConverterBase
{
public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type)
{
ConfigurationConverterBase.ValidateType(value, typeof(TimeSpan));
return ((long)((TimeSpan)value).TotalSeconds).ToString(CultureInfo.InvariantCulture);
}
public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data)
{
long seconds;
try {
seconds = long.Parse((string)data, CultureInfo.InvariantCulture);
} catch {
throw new ArgumentException(System.SR.Converter_timespan_not_in_second);
}
return TimeSpan.FromSeconds(seconds);
}
}
}