InfiniteIntConverter
Converts between a string and the standard infinite or integer value.
using System.ComponentModel;
using System.Globalization;
namespace System.Configuration
{
public sealed class InfiniteIntConverter : ConfigurationConverterBase
{
public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type)
{
ValidateType(value, typeof(int));
if ((int)value != 2147483647)
return ((int)value).ToString(CultureInfo.InvariantCulture);
return "Infinite";
}
public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data)
{
return ((string)data == "Infinite") ? 2147483647 : Convert.ToInt32((string)data, 10);
}
}
}