System.ComponentModel.DebugTypeDescriptor.ComponentEntry.GetEditor C# (CSharp) Method

GetEditor() public method

public GetEditor ( Type editorBaseType ) : object
editorBaseType System.Type
return object
            public object GetEditor(Type editorBaseType) {
                object editor = null;

                // Check the editors we've already created for this type.
                //
                lock(this) {
                    if (editorTypes != null) {
                        for (int i = 0; i < editorCount; i++) {
                            if (editorTypes[i] == editorBaseType) {
                                return editors[i];
                            }
                        }
                    }
                }

                // If one wasn't found, then we must go through the attributes.
                //
                if (editor == null) {
                    AttributeCollection attrs = GetAttributes(null);

                    for (int i = 0; i < attrs.Count; i++) {

                        if (attrs[i] is EditorAttribute) {
                            EditorAttribute attr = (EditorAttribute)attrs[i];
                            Type attrEditorBaseType = GetTypeFromName(attr.EditorBaseTypeName);
                            
                            if (attrEditorBaseType != null && attrEditorBaseType == editorBaseType) {
                                Type type = GetTypeFromName(attr.EditorTypeName);
    
                                if (type != null) {
                                    editor = CreateInstance(type);
                                    break;
                                }
                            }
                        }
                    }
                    
                    // Check our set of intrinsic editors.  These are provided by an external party.
                    //
                    if (editor == null) {
                        Hashtable intrinsicEditors = DebugTypeDescriptor.GetEditorTable(editorBaseType);
                        if (intrinsicEditors != null) {
                            editor  = SearchIntrinsicTable(intrinsicEditors);
                        }
                    }
                    
                    // As a quick sanity check, check to see that the editor we got back is of 
                    // the correct type.
                    //
                    if (editor != null && !editorBaseType.IsInstanceOfType(editor)) {
                        Debug.Fail("Editor " + editor.GetType().FullName + " is not an instance of " + editorBaseType.FullName + " but it is in that base types table.");
                        editor = null;
                    }
                        
                    // Now, another slot in our editor cache for next time
                    //
                    lock(this) {
                    
                        // we do a redundant check here for the editor, just in 
                        // case another thread added it.  We could have locked
                        // the entire method, but with all of the other
                        // callouts from this method deadlock becomes more probable.
                        //
                        // This is very safe, but I'm not sure there are any
                        // bad consequences of having duplicate editor types in the
                        // array.  Better to be safe, but we do take an ever so minor
                        // hit here...
                        //
                        bool redundantEditor = false;
                        
                        if (editorTypes != null) {
                            for (int i = 0; i < editorCount; i++) {
                                if (editorTypes[i] == editorBaseType) {
                                    redundantEditor = true;
                                    break;
                                }
                            }
                        }
                    
                        if (!redundantEditor) {
                            if (editorTypes == null) {
                                editorTypes = new Type[5];
                                editors = new object[5];
                            }
            
                            if (editorCount >= editorTypes.Length) {
                                Type[] newTypes = new Type[editorTypes.Length * 2];
                                object[] newEditors = new object[editors.Length * 2];
                                Array.Copy(editorTypes, newTypes, editorTypes.Length);
                                Array.Copy(editors, newEditors, editors.Length);
                                editorTypes = newTypes;
                                editors = newEditors;
                            }
            
                            editorTypes[editorCount] = editorBaseType;
                            editors[editorCount++] = editor;
                        }
                    }
                }

                return editor;
            }

Same methods

DebugTypeDescriptor.ComponentEntry::GetEditor ( object component, Type editorBaseType ) : object