/// <summary> /// Edits the specified object's value using the editor style indicated by <seealso cref="UITypeEditor.GetEditStyle()"/>. /// </summary> /// <param name="context"> /// An <see cref="ITypeDescriptorContext"/> that can be used to gain additional context information. /// </param> /// <param name="provider"> /// An <see cref="IServiceProvider"/> that this editor can use to obtain services. /// </param> /// <param name="value"> /// The object to edit. /// </param> /// <returns> /// The fully qualifed type name for the chosen type. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { Debug.Assert(provider != null, "No service provider; we cannot edit the value"); if (provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); Debug.Assert(edSvc != null, "No editor service; we cannot edit the value"); if (edSvc != null) { IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); string currentTypeName = value as string; Type currentType = (currentTypeName == null) ? value as Type : Type.GetType(currentTypeName, false); BaseTypeAttribute baseTypeAttribute = GetBaseType(context); using (TypeSelectorUI form = new TypeSelectorUI(currentType, baseTypeAttribute.BaseType, baseTypeAttribute.TypeSelectorIncludes, baseTypeAttribute.ConfigurationType)) { if (service.ShowDialog(form) == DialogResult.OK) { if (form.SelectedType != null) { currentType = form.SelectedType; } } } if (currentType != null) { return(currentType.AssemblyQualifiedName); } } } return(value); }
/// <summary> /// <para>Edits the specified object's value using the editor style indicated by <seealso cref="UITypeEditor.GetEditStyle"/>.</para> /// </summary> /// <param name="context"> /// <para>An <see cref="ITypeDescriptorContext"/> that can be used to gain additional context information.</para> /// </param> /// <param name="provider"> /// <para>An <see cref="IServiceProvider"/> that this editor can use to obtain services.</para> /// </param> /// <param name="value"> /// <para>The object to edit.</para> /// </param> /// <returns> /// The fully qualifed type name for the chosen type. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { Debug.Assert(provider != null, "No service provider; we cannot edit the value"); if (provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); Debug.Assert(edSvc != null, "No editor service; we cannot edit the value"); if (edSvc != null) { IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); string currentTypeName = (string)value; Type currentType = null; if ((currentTypeName != null) && (currentTypeName.Length != 0)) { currentType = Type.GetType(currentTypeName, false); } BaseTypeAttribute baseTypeAttribute = this.GetBaseType(context); using (TypeSelectorUI form = new TypeSelectorUI(currentType, baseTypeAttribute.BaseType, baseTypeAttribute.IncludeFlags)) { if (service.ShowDialog(form) == DialogResult.OK) { if (form.SelectedType != null) { currentTypeName = form.SelectedType.AssemblyQualifiedName; } } } return(currentTypeName); } } return(value); }
/// <devdoc> /// Get the base type of the object to use to filter possible types. /// </devdoc> private static BaseTypeAttribute GetBaseType(ITypeDescriptorContext context) { BaseTypeAttribute baseTypeAttribute = null; foreach (Attribute attribute in context.PropertyDescriptor.Attributes) { baseTypeAttribute = attribute as BaseTypeAttribute; if (null != baseTypeAttribute) { break; } } if (baseTypeAttribute == null) { throw new InvalidOperationException(Resources.ExceptionNoBaseTypeAttribute); } return(baseTypeAttribute); }
/// <devdoc> /// Get the base type of the object to use to filter possible types. /// </devdoc> private BaseTypeAttribute GetBaseType(ITypeDescriptorContext context) { BaseTypeAttribute baseTypeAttribute = null; foreach (Attribute attribute in context.PropertyDescriptor.Attributes) { if (attribute is BaseTypeAttribute) { baseTypeAttribute = ((BaseTypeAttribute)attribute); break; } } if (baseTypeAttribute == null) { throw new InvalidOperationException(SR.ExceptionNoBaseTypeAttribute); } return(baseTypeAttribute); }