/// <summary> /// Edits the value of the specified object using the editor style indicated by <seealso cref="UITypeEditor.GetEditStyle(ITypeDescriptorContext)"/>. /// </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 new value of the object.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (null == context) { return(null); } if (null == provider) { return(null); } IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (service != null) { ReferenceTypeAttribute refTypeAttribute = GetReferenceType(context); ConfigurationNode currentNode = (ConfigurationNode)context.Instance; ConfigurationApplicationNode appNode = GetApplicationNode(currentNode); ConfigurationNode contextNode = (refTypeAttribute.LocalOnly) ? currentNode : appNode; ReferenceEditorUI control = new ReferenceEditorUI(contextNode, refTypeAttribute.ReferenceType, (ConfigurationNode)value, service, IsRequired(context)); service.DropDownControl(control); if (control.SelectedNode != null) { Type propertyType = context.PropertyDescriptor.PropertyType; Type selectedNodeType = control.SelectedNode.GetType(); if (propertyType == selectedNodeType || selectedNodeType.IsSubclassOf(propertyType)) { return(control.SelectedNode); } } } return(null); }
/// <summary> /// <para>Edits the value of the specified object using the editor style indicated by <seealso cref="UITypeEditor.GetEditStyle(ITypeDescriptorContext)"/>.</para> /// </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 new value of the object.</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 service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); Debug.Assert(service != null, "No editor service; we cannot edit the value"); if (service != null) { ConfigurationNode currentNode = (ConfigurationNode)context.Instance; ApplicationConfigurationNode appNode = GetApplicationNode(currentNode); ReferenceEditorUI control = new ReferenceEditorUI(appNode, GetReferenceType(context), (ConfigurationNode)value, service, IsRequired(context)); service.DropDownControl(control); if (control.SelectedNode != null) { Type propertyType = context.PropertyDescriptor.PropertyType; Type selectedNodeType = control.SelectedNode.GetType(); if (propertyType == selectedNodeType || selectedNodeType.IsSubclassOf(propertyType)) { return(control.SelectedNode); } } } } return(null); }
/// <summary> /// <para>Edits the value of the specified object using the editor style indicated by <seealso cref="UITypeEditor.GetEditStyle(ITypeDescriptorContext)"/>.</para> /// </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 new value of the object.</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 service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); Debug.Assert(service != null, "No editor service; we cannot edit the value"); if (service != null) { ConfigurationNode currentNode = (ConfigurationNode)context.Instance; ApplicationConfigurationNode appNode = GetApplicationNode(currentNode); ReferenceEditorUI control = new ReferenceEditorUI(appNode, GetReferenceType(context), (ConfigurationNode)value, service, IsRequired(context)); service.DropDownControl(control); if (control.SelectedNode != null) { Type propertyType = context.PropertyDescriptor.PropertyType; Type selectedNodeType = control.SelectedNode.GetType(); if (propertyType == selectedNodeType || selectedNodeType.IsSubclassOf(propertyType)) { return control.SelectedNode; } } } } return null; }