System.ComponentModel.TypeTypeConverter.ConvertFrom C# (CSharp) Method

ConvertFrom() public method

public ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, object value ) : object
context ITypeDescriptorContext
culture System.Globalization.CultureInfo
value object
return object
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string) {
                if (DesignerProperties.IsInDesignTool) {
                    return null;
                }

                string name = (string)value;

                Type type = ParseTypeName(Application.Current, name);
                if (type != null) {
                    return type;
                }
                throw new ArgumentException("The specified value is not a valid type name.");
            }
            return base.ConvertFrom(value);
        }

Usage Example

Exemplo n.º 1
0
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			TypeTypeConverter converter = new TypeTypeConverter();

			value = converter.ConvertFrom(context, CultureInfo.CurrentCulture, value);
			value = base.EditValue(context, provider, value);
			value = converter.ConvertTo  (context, CultureInfo.CurrentCulture, value, typeof(string));

			return value;
		}