IExtenderProviderService Interface

Definition

Provides an interface for adding and removing extender providers at design time.

C#
public interface IExtenderProviderService

Examples

The following example demonstrates using the IExtenderProviderService from a designer to add and remove an IExtenderProvider implementation.

C#
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace ExtenderServiceExample
{    
    // This designer adds a ComponentExtender extender provider, 
    // and removes it when the designer is destroyed.
    public class ExtenderServiceDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        // A local reference to an obtained IExtenderProviderService.
        private IExtenderProviderService localExtenderServiceReference;
        // An IExtenderProvider that this designer supplies.
        private ComponentExtender extender;
        
        public ExtenderServiceDesigner()
        {
        }

        public override void Initialize(System.ComponentModel.IComponent component)
        {
            base.Initialize(component);

            // Attempts to obtain an IExtenderProviderService.
            IExtenderProviderService extenderService = (IExtenderProviderService)component.Site.GetService(typeof(IExtenderProviderService));
            if( extenderService != null )
            {
                // If the service was obtained, adds a ComponentExtender 
                // that adds an "ExtenderIndex" integer property to the 
                // designer's component.
                extender = new ComponentExtender();                
                extenderService.AddExtenderProvider( extender );
                localExtenderServiceReference = extenderService;
            }
            else
            {
                MessageBox.Show("Could not obtain an IExtenderProviderService.");
            }
        }

        protected override void Dispose(bool disposing)
        {
            // Removes any previously added extender provider.
            if( localExtenderServiceReference != null )
            {
                localExtenderServiceReference.RemoveExtenderProvider( extender );
                localExtenderServiceReference = null;
            }            
        }
    }
    
    // IExtenderProviderImplementation that adds an integer property 
    // named "ExtenderIndex" to any design-mode document object.
    [ProvidePropertyAttribute("ExtenderIndex", typeof(IComponent))]
    public class ComponentExtender : System.ComponentModel.IExtenderProvider
    {
        // Stores the value of the property to extend a component with.
        public int index = 0;        
    
        public ComponentExtender()
        {
        }

        public bool CanExtend(object extendee)
        {         
            // Extends any type of object.
            return true;
        }

        public int GetExtenderIndex(IComponent component)
        {
            return index;
        }

        public void SetExtenderIndex(IComponent component, int index)
        {
            this.index = index;
        }
    }

    // Example UserControl associated with the ExtenderServiceDesigner.
    [DesignerAttribute(typeof(ExtenderServiceDesigner))]
    public class ExtenderServiceTestControl : System.Windows.Forms.UserControl
    {		
        public ExtenderServiceTestControl()
        {						
        }
    }
}

Remarks

Typically, only components that have been added to a container offer extender providers. The IExtenderProviderService allows you to extend this capability to objects that are not in the container.

Methods

AddExtenderProvider(IExtenderProvider)

Adds the specified extender provider.

RemoveExtenderProvider(IExtenderProvider)

Removes the specified extender provider.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also