System.ComponentModel.TypeDescriptor.GetEditor C# (CSharp) Method

GetEditor() public static method

Gets an editor with the specified base type for the specified type.
public static GetEditor ( Type type, Type editorBaseType ) : object
type System.Type
editorBaseType System.Type
return object
        public static object GetEditor(Type type, Type editorBaseType)
        {
            if (editorBaseType == null)
            {
                throw new ArgumentNullException(nameof(editorBaseType));
            }

            return GetDescriptor(type, "type").GetEditor(editorBaseType);
        }

Same methods

TypeDescriptor::GetEditor ( object component, Type editorBaseType ) : object
TypeDescriptor::GetEditor ( object component, Type editorBaseType, bool noCustomTypeDesc ) : object

Usage Example

Example #1
0
        /// <summary>
        ///    <para>
        ///       Gets an editor of the specified type.
        ///    </para>
        /// </summary>
        public virtual object GetEditor(Type editorBaseType)
        {
            object editor = null;

            // Always grab the attribute collection first here, because if the metadata version
            // changes it will invalidate our editor cache.
            AttributeCollection attrs = Attributes;

            // Check the editors we've already created for this type.
            //
            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)
            {
#if FEATURE_EDITORATTRIBUTE
                for (int i = 0; i < attrs.Count; i++)
                {
                    EditorAttribute attr = attrs[i] as EditorAttribute;
                    if (attr == null)
                    {
                        continue;
                    }

                    Type editorType = GetTypeFromName(attr.EditorBaseTypeName);

                    if (editorBaseType == editorType)
                    {
                        Type type = GetTypeFromName(attr.EditorTypeName);
                        if (type != null)
                        {
                            editor = CreateInstance(type);
                            break;
                        }
                    }
                }
#endif

                // Now, if we failed to find it in our own attributes, go to the
                // component descriptor.
                //
                if (editor == null)
                {
                    editor = TypeDescriptor.GetEditor(PropertyType, editorBaseType);
                }

                // Now, another slot in our editor cache for next time
                //
                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);
        }
All Usage Examples Of System.ComponentModel.TypeDescriptor::GetEditor