ServiceModelTimeSpanValidator.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Configuration / ServiceModelTimeSpanValidator.cs / 1 / ServiceModelTimeSpanValidator.cs

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

namespace System.ServiceModel.Configuration 
{
    using System; 
    using System.Configuration; 
    using System.Globalization;
    using System.ComponentModel; 

    // deals with
    [AttributeUsage(AttributeTargets.Property)]
    sealed class ServiceModelTimeSpanValidatorAttribute : ConfigurationValidatorAttribute 
    {
        TimeSpanValidatorAttribute innerValidatorAttribute; 
 
        public ServiceModelTimeSpanValidatorAttribute()
        { 
            this.innerValidatorAttribute = new TimeSpanValidatorAttribute();
            this.innerValidatorAttribute.MaxValueString = TimeoutHelper.MaxWait.ToString();
        }
 
        public override ConfigurationValidatorBase ValidatorInstance
        { 
            get 
            {
                return new TimeSpanOrInfiniteValidator(MinValue, MaxValue); 
            }
        }

        public TimeSpan MinValue 
        {
            get 
            { 
                return this.innerValidatorAttribute.MinValue;
            } 
        }

        public string MinValueString
        { 
            get
            { 
                return this.innerValidatorAttribute.MinValueString; 
            }
            set 
            {
                this.innerValidatorAttribute.MinValueString = value;
            }
        } 

        public TimeSpan MaxValue 
        { 
            get
            { 
                return this.innerValidatorAttribute.MaxValue;
            }
        }
 
        public string MaxValueString
        { 
            get 
            {
                return this.innerValidatorAttribute.MaxValueString; 
            }
            set
            {
                this.innerValidatorAttribute.MaxValueString = value; 
            }
        } 
    } 

    class TimeSpanOrInfiniteValidator : TimeSpanValidator 
    {
        public TimeSpanOrInfiniteValidator(TimeSpan minValue, TimeSpan maxValue)
            : base(minValue, maxValue)
        { 
        }
 
        public override void Validate(object value) 
        {
            if (value.GetType() == typeof(TimeSpan) && 
                (TimeSpan)value == TimeSpan.MaxValue)
            {
                return; // we're good
            } 

            base.Validate(value); 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

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