IsValid() 공개 메소드

public IsValid ( ITypeDescriptorContext context, object value ) : bool
context ITypeDescriptorContext
value object
리턴 bool
예제 #1
0
 /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
 /// <param name="value">The <see cref="T:System.Object" /> to test for validity. </param>
 public override bool IsValid(ITypeDescriptorContext context, object value)
 {
     if (underlyingTypeConverter != null)
     {
         return(underlyingTypeConverter.IsValid(context, value));
     }
     return(base.IsValid(context, value));
 }
예제 #2
0
        /// <summary>
        ///    <para>Gets a value indicating whether the given value object is valid for this type.</para>
        /// </summary>
        public override bool IsValid(ITypeDescriptorContext context, object value)
        {
            if (_simpleTypeConverter != null)
            {
                object unwrappedValue = value;
                if (unwrappedValue == null)
                {
                    return(true); // null is valid for nullable.
                }
                else
                {
                    return(_simpleTypeConverter.IsValid(context, unwrappedValue));
                }
            }

            return(base.IsValid(context, value));
        }
 /// <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>
 /// <c>true</c> if the specified value is valid for this object; otherwise, <c>false</c>.
 /// </returns>
 public override bool IsValid(System.ComponentModel.ITypeDescriptorContext context, object value)
 {
     if (value != null && value.GetType() == typeof(string))
     {
         // provo a convertirlo
         try
         {
             object val = ConvertFrom(context, CultureInfo.CurrentCulture, value);
             return(true);
         }
         catch (FormatException)
         {
             return(false);
         }
         catch (ArgumentException)
         {
             return(false);
         }
     }
     else
     {
         return(baseTypeConverter.IsValid(context, value));
     }
 }
예제 #4
0
 public static bool Is <TValue>(this string value)
 {
     System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(TValue));
     return(((converter != null) && converter.CanConvertFrom(typeof(string))) && converter.IsValid(value));
 }