TimeSpanOrInfiniteConverter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / System.Runtime.DurableInstancing / System / Runtime / TimeSpanOrInfiniteConverter.cs / 1305376 / TimeSpanOrInfiniteConverter.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------

namespace System.Runtime 
{
    using System; 
    using System.Diagnostics.CodeAnalysis; 
    using System.Globalization;
    using System.ComponentModel; 

    [SuppressMessage(FxCop.Category.Xaml, FxCop.Rule.TypeConvertersMustBePublic,
        Justification = "Only used by discovery, which doesn't support PT")]
    class TimeSpanOrInfiniteConverter : TimeSpanConverter 
    {
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cultureInfo, object value, Type type) 
        { 
            if (value == null)
            { 
                throw Fx.Exception.ArgumentNull("value");
            }

            if (!(value is TimeSpan)) 
            {
                throw Fx.Exception.Argument("value", SRCore.IncompatibleArgumentType(typeof(TimeSpan), value.GetType())); 
            } 

            if ((TimeSpan)value == TimeSpan.MaxValue) 
            {
                return "Infinite";
            }
            else 
            {
                return base.ConvertTo(context, cultureInfo, value, type); 
            } 
        }
 
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo cultureInfo, object data)
        {
            if (string.Equals((string)data, "infinite", StringComparison.OrdinalIgnoreCase))
            { 
                return TimeSpan.MaxValue;
            } 
            else 
            {
                return base.ConvertFrom(context, cultureInfo, data); 
            }
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK