Yaircc.NickNameTypeConverter.ConvertFrom C# (CSharp) Метод

ConvertFrom() публичный Метод

Converts the given object to the type of this converter, using the specified context and culture information.
public ConvertFrom ( ITypeDescriptorContext context, System culture, object value ) : object
context ITypeDescriptorContext An System.ComponentModel.ITypeDescriptorContext that provides a format context.
culture System The System.Globalization.CultureInfo to use as the current culture.
value object The System.Object to convert.
Результат object
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (!(value is string))
            {
                return base.ConvertFrom(context, culture, value);
            }
            else
            {
                string pattern = @"^[\[\]\\`_\^\{\|\}a-zA-Z]{1}[\[\]\\`_\^\{\|\}a-zA-Z0-9\-]+$";
                Regex regex = new Regex(pattern);

                if (!regex.IsMatch(value.ToString()))
                {
                    throw new FormatException(@"Nick names may only contain letters, numbers or one of the special characters below. Names can also not start with a number or hyphen.
                                                test");
                }

                return value;
            }
        }