EditorAttribute 类

定义

指定用于更改属性的编辑器。 此类不能被继承。

public ref class EditorAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=true)]
public sealed class EditorAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All, AllowMultiple=true, Inherited=true)>]
type EditorAttribute = class
    inherit Attribute
Public NotInheritable Class EditorAttribute
Inherits Attribute
继承
EditorAttribute
属性

示例

下面的代码示例创建 MyImage 类。 类标有一个 EditorAttribute ,指定 ImageEditor 作为其编辑器。

[Editor("System.Windows.Forms.ImageEditorIndex, System.Design",
UITypeEditor::typeid)]
public ref class MyImage{
   // Insert code here.
};
[Editor("System.Windows.Forms.ImageEditorIndex, System.Design", 
    typeof(UITypeEditor))]

public class MyImage
{
    // Insert code here.
 }
<Editor("System.Windows.Forms.ImageEditorIndex, System.Design", _
    GetType(UITypeEditor))> _
Public Class MyImage
    ' Insert code here.
End Class

下面的代码示例创建 类的 MyImage 实例,获取类的属性,然后打印 所使用的 myNewImage编辑器的名称。

int main()
{
   // Creates a new component.
   MyImage^ myNewImage = gcnew MyImage;

   // Gets the attributes for the component.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewImage );

   /* Prints the name of the editor by retrieving the EditorAttribute 
       * from the AttributeCollection. */
   EditorAttribute^ myAttribute = dynamic_cast<EditorAttribute^>(attributes[ EditorAttribute::typeid ]);
   Console::WriteLine( "The editor for this class is: {0}", myAttribute->EditorTypeName );
   return 0;
}
public static int Main() {
    // Creates a new component.
    MyImage myNewImage = new MyImage();
 
    // Gets the attributes for the component.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewImage);
 
    /* Prints the name of the editor by retrieving the EditorAttribute 
     * from the AttributeCollection. */
    
    EditorAttribute myAttribute = (EditorAttribute)attributes[typeof(EditorAttribute)];
    Console.WriteLine("The editor for this class is: " + myAttribute.EditorTypeName);
 
    return 0;
 }
Public Shared Sub Main()
    ' Creates a new component.
    Dim myNewImage As New MyImage()
    
    ' Gets the attributes for the component.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewImage)
    
    ' Prints the name of the editor by retrieving the EditorAttribute
    ' from the AttributeCollection. 
    
    Dim myAttribute As EditorAttribute = CType(attributes(GetType(EditorAttribute)), EditorAttribute)
    Console.WriteLine(("The editor for this class is: " & myAttribute.EditorTypeName))

End Sub

注解

编辑属性时,可视化设计器应通过对话框或下拉窗口创建指定编辑器的新实例。

EditorBaseTypeName使用 属性查找此编辑器的基类型。 唯一可用的基类型是 UITypeEditor

EditorTypeName使用 属性可获取与此特性关联的编辑器类型的名称。

有关使用特性的一般信息。 请参阅 属性。 有关设计时属性的详细信息,请参阅 特性和Design-Time支持

构造函数

EditorAttribute()

用默认的编辑器(即不使用任何编辑器)初始化 EditorAttribute 类的新实例。

EditorAttribute(String, String)

用编辑器的类型名称和基类型名称初始化 EditorAttribute 类的新实例。

EditorAttribute(String, Type)

用类型名和基类型来初始化 EditorAttribute 类的新实例。

EditorAttribute(Type, Type)

用类型和基类型初始化 EditorAttribute 类的新实例。

属性

EditorBaseTypeName

获取作为此编辑器查找键的基类或接口的名称。

EditorTypeName

获取 AssemblyQualifiedName 格式的编辑器类的名称。

TypeId

获取此特性类型的唯一 ID。

方法

Equals(Object)

返回给定对象的值是否等于当前的 EditorAttribute

GetHashCode()

返回此实例的哈希代码。

GetType()

获取当前实例的 Type

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。

(继承自 Attribute)

适用于