File: System\Configuration\InfiniteIntConverter.cs
Web Access
Project: src\src\libraries\System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj (System.Configuration.ConfigurationManager)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System.ComponentModel;
using System.Diagnostics;
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));
 
            return (int)value == int.MaxValue ? "Infinite" : ((int)value).ToString(CultureInfo.InvariantCulture);
        }
 
        public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data)
        {
            Debug.Assert(data is string, "data is string");
 
            return (string)data == "Infinite" ? int.MaxValue : Convert.ToInt32((string)data, 10);
        }
    }
}