#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel; 
#endregion

namespace Microsoft.Practices.RecipeFramework.Extensions.Converters
{
    /// <summary>
    /// A converter that validates an absolute Uri string.
    /// For an <see cref="Uri"/> type converter use <see cref="System.UriTypeConverter"/>.
    /// </summary>
    public class UriConverter : StringConverter
    {
        /// <summary>
        /// Returns whether the given value object is valid for this type and for the specified context.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param>
        /// <param name="value">The <see cref="T:System.Object"></see> to test for validity.</param>
        /// <returns>
        /// true if the specified value is valid for this object; otherwise, false.
        /// </returns>
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            bool response = false;

            if(value is string)
            {
                Uri uri;
                response = Uri.TryCreate(value as string, UriKind.Absolute, out uri);
            }

            return response;
        }
    }
}
