System.ComponentModel.DebugTypeDescriptor.CreateDesigner C# (CSharp) Method

CreateDesigner() public static method

public static CreateDesigner ( IComponent component, Type designerBaseType ) : IDesigner
component IComponent
designerBaseType System.Type
return IDesigner
        public static IDesigner CreateDesigner(IComponent component, Type designerBaseType) {
            Type designerType = null;
            IDesigner designer = null;

            Debug.WriteLineIf(CompDescrSwitch.TraceVerbose, "CreateDesigner(" + component.GetType().FullName + ")");
            
            // Get the set of attributes for this type
            //
            AttributeCollection attributes = GetAttributes(component);
            
            for (int i = 0; i < attributes.Count; i++) {
                if (attributes[i] is DesignerAttribute) {
                    DesignerAttribute da = (DesignerAttribute)attributes[i];
                    Type attributeBaseType = Type.GetType(da.DesignerBaseTypeName);
                    if (attributeBaseType != null && attributeBaseType == designerBaseType) {
                        ISite site = component.Site;
                        bool foundService = false;
                        
                        if (site != null) {
                            ITypeResolutionService tr = (ITypeResolutionService)site.GetService(typeof(ITypeResolutionService));
                            if (tr != null) {
                                foundService = true;
                                designerType = tr.GetType(da.DesignerTypeName);
                            }
                        }
                        
                        if (!foundService) {
                            designerType = Type.GetType(da.DesignerTypeName);
                        }
                        
                        Debug.Assert(designerType != null, "It may be okay for the designer not to load, but we failed to load designer for component of type '" + component.GetType().FullName + "' because designer of type '" + da.DesignerTypeName + "'");
                        if (designerType != null) {
                            break;
                        }
                    }
                }
            }
            
            if (designerType != null) {
                designer = (IDesigner)Activator.CreateInstance(designerType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null);
            }
            else {
                Debug.WriteLineIf(CompDescrSwitch.TraceVerbose, "Could not find designer for: " + component.GetType().FullName);
            }
            return designer;
        }